How can I reverse a stack?
- by come pollinate me
I need to write a VB.NET code to reverse the given characters using a stack.
Input: 'S','T','A','C','K'
So far I have input the letters, but I don't know how to get the console to reverse it. I'm a beginner to programming so please excuse my ignorance.
An explanation as to how it's done would also be greatly appreciated.
What I got so far.
Module Module1
Sub Main()
Dim StackObject As New Stack
StackObject.Push("S")
Console.WriteLine(StackObject.Peek)
StackObject.Push("T")
Console.WriteLine(StackObject.Peek)
StackObject.Push("A")
Console.WriteLine(StackObject.Peek)
StackObject.Push("C")
Console.WriteLine(StackObject.Peek)
StackObject.Push("K")
Console.WriteLine(StackObject.Peek)
End Sub
End Module
I just need it to be reversed.
I got it!!
Module Module1
Sub Main()
Dim StackObject As New Stack
StackObject.Push("S")
StackObject.Push("T")
StackObject.Push("A")
StackObject.Push("C")
StackObject.Push("K")
For Each cur As String In StackObject
Console.WriteLine(cur)
Next
End Sub
End Module
That's how it's done.