473,594 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2082
You may not necessarily have to use a stack.
Let's say in VB it may look like:

Dim myTextArray() As Char =
TextBox1.Text.T oCharArray
Array.Reverse(m yTextArray)
Dim reverseString As String
With New System.Text.Str ingBuilder
.Append(myTextA rray)
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*********@ho tmail.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*******@disc ussions.microso ft.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.T oCharArray
Array.Reverse(m yTextArray)
Dim reverseString As String
With New System.Text.Str ingBuilder
.Append(myTextA rray)
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.Collecti ons.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*********@ho tmail.com> wrote in message
news:30******** *************** ***@posting.goo gle.com...
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*********@ho tmail.com> wrote in message
news:30******** *************** ***@posting.goo gle.com...
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******* *******@TK2MSFT NGP10.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*********@ho tmail.com> wrote in message
news:30******** *************** ***@posting.goo gle.com...
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(txt Input.Text))and then another button to display the
stack:

While enumerator.Move Next()
buffer.Append(e numerator.Curre nt)
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_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdDisplay.Clic k
Dim enumerator As IEnumerator = stack.GetEnumer ator
Dim buffer As StringBuilder = New StringBuilder()
Dim count As Integer
word = txtInput.Text
count = word.Length
stack.Push(word )

While enumerator.Move Next()
buffer.Append(e numerator.Curre nt)
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
30083
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 part of the standard, then just disregard this question. Here's some questions I'm confused about, and if you can add anything else, please do so! Is the stack limited for each program?
19
3123
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 (nested), three list views, one tree control with up to 30,000 nodes, maybe 15 comboboxes (half of which have a large recordset as rowsource), 20 or so buttons and around 30 text boxes (not to mention the images, labels, etc and around 1000 lines...
4
3612
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 useful to help me to solve some basic problem which I may not perceive before. I appreciate your help, sincerely.
13
2297
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 property(variable). The string would be a reference type being contained in a value type. Would this filter up and cause the stack to now be a reference type placed on the heap or would it still be on the stack with a pointer used internally to point to a...
5
2014
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 the top most file empty >i.e, something like hiding the files by one step (or one position of stack) >i.e,if someone tries to extract the top most file he see's that it is empty thus assumes the stack to be empty. >can this view be applied...
24
2853
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 are structs, where classes are on the heap... when value types go out of scope the memory is re- allocated, object remain in memory waiting to be cleaned up by the garbage collector, etc, but he responded 'so why not just put say a class on the...
24
6564
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 the stack pointer should go upwards when there are "push" operations, and stack pointer should go downards when there are "pop" operations?? If this is the case, the address should go upwards (increasing) or downards (decreasing) then? i.e....
148
5472
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
5512
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 place? I can see two definite disadvantages with this: 1) deeply nested recursive calls to a function (especially if it defines
0
7876
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
6654
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.