473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Stack question

What up everyone,

I have to write a program that uses a stack to determine whether a
string is a palindrome (a string that is spelled identically backward
and forward). The program has to ignore spaces, case sensitivity and
punctuation.
I need three text boxes. The first will be for input of the string.
The second will display the string when the "check" button is clicked
and the result of the analysis (string is a palindrome or is not a
palindrome). The third text box should show how the two strings
compared, with the first one being displayed forward and the second
backward.
I have to use a stack for this problem and I'm kind of lost. If anyone
can get me started or show me some examples, that would be awesome.

TIA,
LedZep
Nov 20 '05 #1
8 2060
You may not necessarily have to use a stack.
Let's say in VB it may look like:

Dim myTextArray() As Char =
TextBox1.Text.ToCharArray
Array.Reverse(myTextArray)
Dim reverseString As String
With New System.Text.StringBuilder
.Append(myTextArray)
reverseString = .ToString
End With

Hope that is enough for you to start...
-----Original Message-----
What up everyone,

I have to write a program that uses a stack to determine whether astring is a palindrome (a string that is spelled identically backwardand forward). The program has to ignore spaces, case sensitivity andpunctuation.
I need three text boxes. The first will be for input of the string.The second will display the string when the "check" button is clickedand the result of the analysis (string is a palindrome or is not apalindrome). The third text box should show how the two stringscompared, with the first one being displayed forward and the secondbackward.
I have to use a stack for this problem and I'm kind of lost. If anyonecan get me started or show me some examples, that would be awesome.
TIA,
LedZep
.

Nov 20 '05 #2
"LedZep" <wa*********@hotmail.com> wrote...
I have to write a program that uses a stack to determine whether a
string is a palindrome (a string that is spelled identically backward
and forward). The program has to ignore spaces, case sensitivity and
punctuation.
It sounds surprisingly like a homework assignment :-)
I have to use a stack for this problem and I'm kind of lost. If anyone
can get me started or show me some examples, that would be awesome.


You might not go for it but would you post what you have so far or ask a
specific question? Do you know what a stack is and how it works? Have you
been able to push anything onto a stack and pop it off again? I don't think
we quite know where you are stuck.
Nov 20 '05 #3
I think the homework assignment demands that he use a stack so he can get an
understanding of how a stack works. We might let him try first.

"Sergey Poberezovskiy" <an*******@discussions.microsoft.com> wrote in
message news:05****************************@phx.gbl...
You may not necessarily have to use a stack.
Let's say in VB it may look like:

Dim myTextArray() As Char =
TextBox1.Text.ToCharArray
Array.Reverse(myTextArray)
Dim reverseString As String
With New System.Text.StringBuilder
.Append(myTextArray)
reverseString = .ToString
End With

Hope that is enough for you to start...
-----Original Message-----
What up everyone,

I have to write a program that uses a stack to determine

whether a
string is a palindrome (a string that is spelled

identically backward
and forward). The program has to ignore spaces, case

sensitivity and
punctuation.
I need three text boxes. The first will be for input of

the string.
The second will display the string when the "check"

button is clicked
and the result of the analysis (string is a palindrome

or is not a
palindrome). The third text box should show how the two

strings
compared, with the first one being displayed forward and

the second
backward.
I have to use a stack for this problem and I'm kind of

lost. If anyone
can get me started or show me some examples, that would

be awesome.

TIA,
LedZep
.

Nov 20 '05 #4
LedZep,
Have you looked at the System.Collections.Stack class?

It has methods to Push & Pop an item onto the stack, it also has a method
Peek to check the top item on the stack.

I would not expect the assignment to be that you need to write the stack
class itself.

Hope this helps
Jay

"LedZep" <wa*********@hotmail.com> wrote in message
news:30**************************@posting.google.c om...
What up everyone,

I have to write a program that uses a stack to determine whether a
string is a palindrome (a string that is spelled identically backward
and forward). The program has to ignore spaces, case sensitivity and
punctuation.
I need three text boxes. The first will be for input of the string.
The second will display the string when the "check" button is clicked
and the result of the analysis (string is a palindrome or is not a
palindrome). The third text box should show how the two strings
compared, with the first one being displayed forward and the second
backward.
I have to use a stack for this problem and I'm kind of lost. If anyone
can get me started or show me some examples, that would be awesome.

TIA,
LedZep

Nov 20 '05 #5
So what if its a homework assignment?? My teacher sucks and the book
sucks. How else am I supposed to learn, the .NET help menus? Please.
If anyone wants to help me, awesome, I thought thats what these
newsgroups were supposed to be all about. If not fine.

LedZep
Nov 20 '05 #6
Basically I dont know what a stack is or why I have to use it. Why
cant I just do it how Sergey says. I dont want someone to write the
entire code and send it to me. I just want to understand what the hell
I'm doing and why. Thats the problem with my teacher - he does the
complete opposite... which is nothing.

Thanks for any replies...

LedZep
Nov 20 '05 #7
LedZep,
It sounds like you realize there is a difference of someone doing the
assignment for you, which is cheating. And you asking in the newsgroup what
a stack is and how it works. Some students don't realize this or care about
this, they simple want the assignment done, hence my and Tom's caution.

However the assignment is designed to get you to understand how a stack
works, so answering the question is one of those gray areas when it could be
considered cheating.

I also hope you realize that if your teacher is truly as bad as you make him
sound and other students feel this way, that is a matter for the
administration of the school.

Any way, what is a stack:

http://abstractvb.com/code.asp?A=1023

A stack is an object that stores other items (objects), where these other
items can be retrieved in a LIFO (Last In, First Out) manner. To put items
on the stack you use stack.Push(item) to remove items from the stack you use
item = stack.Pop, where stack is your Stack variable.

Think of a stack as the dispenser for trays or plates at a cafeteria. When
the kitchen help puts more trays on the top of the dispenser the old ones
are pushed down, when you pick up a tray to get your food you get the last
one put on the dispenser, its popped off the top.

If you think of how the stack works last in, first out, think how that could
be used to reverse the order of a string.

If you take the first character of a string and put it on the stack, if you
take the next character of a string and put it on the stack...

If you pop a character off the stack, and put it on the end of a new string,
if you pop another character off the stack and put it on the end of a new
string...

Hope this helps
Jay

"LedZep" <wa*********@hotmail.com> wrote in message
news:30**************************@posting.google.c om...
Basically I dont know what a stack is or why I have to use it. Why
cant I just do it how Sergey says. I dont want someone to write the
entire code and send it to me. I just want to understand what the hell
I'm doing and why. Thats the problem with my teacher - he does the
complete opposite... which is nothing.

Thanks for any replies...

LedZep

Nov 20 '05 #8
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<ew**************@TK2MSFTNGP10.phx.gbl>...
LedZep,
It sounds like you realize there is a difference of someone doing the
assignment for you, which is cheating. And you asking in the newsgroup what
a stack is and how it works. Some students don't realize this or care about
this, they simple want the assignment done, hence my and Tom's caution.

However the assignment is designed to get you to understand how a stack
works, so answering the question is one of those gray areas when it could be
considered cheating.

I also hope you realize that if your teacher is truly as bad as you make him
sound and other students feel this way, that is a matter for the
administration of the school.

Any way, what is a stack:

http://abstractvb.com/code.asp?A=1023

A stack is an object that stores other items (objects), where these other
items can be retrieved in a LIFO (Last In, First Out) manner. To put items
on the stack you use stack.Push(item) to remove items from the stack you use
item = stack.Pop, where stack is your Stack variable.

Think of a stack as the dispenser for trays or plates at a cafeteria. When
the kitchen help puts more trays on the top of the dispenser the old ones
are pushed down, when you pick up a tray to get your food you get the last
one put on the dispenser, its popped off the top.

If you think of how the stack works last in, first out, think how that could
be used to reverse the order of a string.

If you take the first character of a string and put it on the stack, if you
take the next character of a string and put it on the stack...

If you pop a character off the stack, and put it on the end of a new string,
if you pop another character off the stack and put it on the end of a new
string...

Hope this helps
Jay

"LedZep" <wa*********@hotmail.com> wrote in message
news:30**************************@posting.google.c om...
Basically I dont know what a stack is or why I have to use it. Why
cant I just do it how Sergey says. I dont want someone to write the
entire code and send it to me. I just want to understand what the hell
I'm doing and why. Thats the problem with my teacher - he does the
complete opposite... which is nothing.

Thanks for any replies...

LedZep


All right,

Here's my code. Two questions: 1.) Why doesnt the enumerator display
the the item(s) pushed onto the stack in txtOutput??? When I have a
separate button to push an item onto a stack
(stack.Push(txtInput.Text))and then another button to display the
stack:

While enumerator.MoveNext()
buffer.Append(enumerator.Current)
txtOutput.Text = buffer.ToString
End While

it works fine. Why cant I do both push and display in the same button?

2.) Any suggestions on how to push "word" onto the stack letter by
letter? I tried using a loop where

count = word.Length

Do while i =< count
stack.Push(word.Chars(n))
n = n + 1
i = i + 1
Loop
This kinda works because it displays the stack LIFO-esque (the word
appears backwards when displayed). So then how would I display "word"
in non-LIFO (so that "word" appears correctly spelled)? Is Chars the
right way to enter "word" letter by letter? Should I make it an
array??? Kinda confused....

Dim stack As New stack()
Dim word As String

Private Sub cmdDisplay_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDisplay.Click
Dim enumerator As IEnumerator = stack.GetEnumerator
Dim buffer As StringBuilder = New StringBuilder()
Dim count As Integer
word = txtInput.Text
count = word.Length
stack.Push(word)

While enumerator.MoveNext()
buffer.Append(enumerator.Current)
txtOutput.Text = buffer.ToString
End While

End Sub

Any help is MUCH APPRECIATED,

LedZep
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
13
by: gmccallum | last post by:
General Info: A struct is stored on the stack and a class on the heap. A struct is a value type while a class is a reference type. Question: What if a struct contains a string...
5
by: srikanth | last post by:
is it possible not to decrement the top variable after we remove(or retreive) a file from a stack >MY IDEA is:> if top is not decremented the stack is like it has some files existing in it with...
24
by: arcticool | last post by:
I had an interview today and I got destroyed :( The question was why have a stack and a heap? I could answer all the practical stuff like value types live on the stack, enums are on the stack, as...
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
148
by: onkar | last post by:
Given the following code & variable i . int main(int argc,char **argv){ int i; printf("%d\n",i); return 0; } here i is allocated from bss or stack ?
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.