using System;
using System.Collections;
class Program
{
static void Main()
{
Stack stk = new Stack();
Console.WriteLine("Add Numbers to the Stack");
foreach (int n in new int[3] { 1, 2, 3 })
{
stk.Push(n);
Console.WriteLine(n);
}
Console.WriteLine("Display Numbers from the Stack");
foreach (int n in stk)
{
Console.WriteLine(n);
}
Console.WriteLine("Remove Numbers from the Stack");
while (stk.Count != 0)
{
int n = (int)stk.Pop();
Console.WriteLine(n);
}
Console.ReadKey();
}
}
|
Imports System.Collections
Class Program
Private Shared Sub Main()
Dim stk As New Stack()
Console.WriteLine("Add Numbers to the Stack")
For Each n As Integer In New Integer(2) {1, 2, 3}
stk.Push(n)
Console.WriteLine(n)
Next
Console.WriteLine("Display Numbers from the Stack")
For Each n As Integer In stk
Console.WriteLine(n)
Next
Console.WriteLine("Remove Numbers from the Stack")
While stk.Count <> 0
Dim n As Integer = CInt(stk.Pop())
Console.WriteLine(n)
End While
Console.ReadKey()
End Sub
End Class
|