Published using Google Docs
Stacks
Updated automatically every 5 minutes

  

              

Stack

 

Stack is a list with restriction that insertions and deletions can be performed at only one end, called the top. The fundamental operations on stack are Push, which is equivalent to insert, and Pop, which deletes the most recently inserted element.

 

Push(s,x):- To insert an element  ‘x’ onto the stack, First we check whether the stack  ‘s’ has enough space to insert an element into a stack or not. If there is enough space then put ‘x’ into the stack. Otherwise we give a message “Stack over flow”.

 

 

Pop(s):- To delete an element from the top of the stack, First We check whether the‘s’ is empty or not. If stack isn’t empty then access the element at the top of the stack. Otherwise (i.e. Stack‘s’ is empty), we give the message that “There is no element in the stack (or) stack under flow”.

 

 

Note: - Stacks are some times known as LIFO (Last In First Out) lists.

 

Applications of Stacks:-

 

1.        For checking the balancing symbols (i.e. nested balanced parenthesis).

2.        For converting the infix expression to postfix expression.

3.        For evaluating the postfix expression.

4.        To keep track of procedure and function calls and how recursion is actually implemented.