Sunday, September 20, 2015

Stack

Stack is a linear data structure which follows a particular order in which the operations are performed. Order is LIFO(Last In First Out) or FILO(First In Last Out)

Three main operations of a stack are :

  1. Push
  2. Pop
  3. Peek or Top
Stack


Push
The Push Operation pushes an element into the stack.

Pop
Pop operation removes the top most element in the stack.

Peek
Peek or top operation returns the top most value of the stack.


To understand stack, you can assume a pile of books placed one over the other.To get the last book in the stack, one needs to take away all the books before the last book.


Applications of Stack
  1. Recursion
  2. Tower of Hanoi
  3. Converting Infix to Postfix.


Stack can be implemented in two different ways: 
  1. Stack Implementation using Arrays 
  2. Stack Implementation using Linked list
The implemented codes are carried out into separate blogs in the above given links.

More stack related blogs