Push and Pop operations on Stack in C#.


Push Operations : Push Operations are used to insert elements into stack.

Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
//Display stack elements after Push
foreach (int i in stack)
  {
     Console.WriteLine(i);
  }


Pop Operations : Pop Operations are used to remove elements from the stack.

stack.Pop();
//Display stack elements after Pop
foreach (int i in stack)
  {
     Console.WriteLine(i);
  }


Peek Operation : Peek Operation is used to get the top element from the stack.

int top = stack.Peek();
//Display Peek element from the Stack
Console.WriteLine(top);