How to reverse words using a stack
Posted on 2004-04-19
I am a graduate student taking a second level C# course. This is homework....so don't get snippy trying to sniff me out :)
2 text boxes..and 1 button.
The click event on button1 should read whatever word (or number) is typed in textbox1 and output to textbox2 whether or not the input in textbox1 is a palindrome. (ie "level" in textbox1, when button1 is clicked, textbox2 will read "level is a palindrome"...whereas "lever" in textbox1, when button1 is clicked, textbox2 will read "lever is NOT a palindrome".) This needs to work for words or numbers. I've done stuff like this before in C++ using various functions, but am unclear how to do this in c# using a stack.
The core dificulty for me lies in the not knowing how to separate the characters within the stack. Its simple enough to pop off words in reverse order (ie push green, push red.....pop red, pop green), but how do I do that with the actual characters?
Any thoughts would be greatly appreciated.