L
LedZep
This program has to use 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 have to somehow take the input from the txtbox, stack
it letter by letter onto a stack, then display it written forward and
below it written backwards. I understand the concept of stacks -- I
just need a little push in the right direction.
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
string is a palindrome (a string that is spelled identically backward
and forward). The program has to ignore spaces, case sensitivity and
punctuation. I have to somehow take the input from the txtbox, stack
it letter by letter onto a stack, then display it written forward and
below it written backwards. I understand the concept of stacks -- I
just need a little push in the right direction.
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