stack in C#
For Example: Write a program to demonstrate the use of stack.
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
Stack st = new Stack();
st.Push('A');
st.Push('R');
st.Push('Y');
st.Push('A');
Console.WriteLine("Current
stack: ");
foreach (char c in st)
{
Console.Write(c + "
");
}
Console.WriteLine();
st.Push('N');
st.Push('@');
Console.WriteLine("The next poppable
value in stack: {0}", st.Peek());
Console.WriteLine("Current
stack: ");
foreach (char c in st)
{
Console.Write(c + "
");
}
Console.WriteLine();
Console.WriteLine("Removing
values ");
st.Pop();
st.Pop();
st.Pop();
Console.WriteLine("Current
stack: ");
foreach (char c in st)
{
Console.Write(c + "
");
}
Console.ReadLine();
}
}
}
Output:
Comments
Post a Comment