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(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 1 1196
Since you want to display the word first forward, then backward, why don't
you display it once as you push the letters onto the stack, and again as you
pull them off. Then you can do it in one routine easily. This also shows you
how to push the letters onto the stack one at a time:
Private Sub cmdDisplay_Clic k(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles cmdDisplay.Clic k
Dim st As New Stack
Dim count As Integer
Dim word As String
word = txtInput.Text
txtOutput.Clear ()
For i As Integer = 0 To word.Length - 1
txtOutput.Appen dText(word.Char s(i))
st.Push(word.Ch ars(i))
Next
Dim enumerator As IEnumerator = st.GetEnumerato r
While enumerator.Move Next()
txtOutput.Appen dText(enumerato r.Current.ToStr ing)
End While
End Sub
"LedZep" <wa*********@ho tmail.com> wrote in message
news:30******** *************** ***@posting.goo gle.com... 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(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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Madhu Gopinathan |
last post by:
Hi All,
I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor. Each task is processed in a separate thread. Each of the executer threads is an STA thread, and it goes ahead and executes the task.
No problems are encountered when tasks are executed one at a time, but when multiple tasks are executed...
|
by: Rich Kucera |
last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version
configurations inevitable
Will have to wait to see what the impact of problems such as
http://bugs.php.net/bug.php?id=33643 to the application world. We may
wait for a suitable popular resolution and jump to that version in the
future. There's already a rift between PHP4 and PHP5, and then further
developments such as these create another, splitting the camp into 4....
|
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...
|
by: Daniel |
last post by:
Hi,
I have a question regarding the memory managment in stl stacks. I want
to use stacks to store a very large amount of numbers (some millions),
thus I'm interested in how the stack behaves when it has to increase
its memory.
http://www.sgi.com/tech/stl/stack.html, the stacks default underlying
container is a deque that has amortized constant time insertion and
removal of elements.
|
by: raghuveer |
last post by:
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have
#include<stdio.h>
#include<conio.h>
int top;
int bot;
void main()
{
| |
by: satan |
last post by:
I need a help in my method equalStack in my class StackClass.
public class StackClass
{
private int maxStackSize; //variable to store the maximum
//stack size
private int stackTop; //variable to point to the top
//of the stack
private DataElement list; //array of reference variables
|
by: dav3 |
last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and have yet to find a solution.
My program is supposed to read in a txt file which contains 2 lines of numbers. Program reads the file and stores each line as a string, then converts each character to an integer. Once char is converted to an int the...
|
by: shahrossi |
last post by:
Exercise question:
1. Write a program that copies the contents of one stack into another. A function
named copystack receives 2 stacks the source stack and the destination stack.
The order of the stacks must be identical. (Hint: Use a temporary stack to
preserve the order)
2. Write a program that reads a text file, one in a line at a time and prints the line
as it was read and then prints the line with its text reversed. Print a blank...
|
by: Mhel |
last post by:
I'm really having a hard time with Stack...
The problem goes this way:
Create an array ( a ).
If choice == 1, push number.
If choice == 2, pop number,
If choice == 3, display stack.
If choice == 0 quit.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |