Wednesday, 19 October 2016

STACK A stack is a linear data structure in which insertion and deletion of elements are done at only one end, which... thumbnail 1 summary
STACK


  • A stack is a linear data structure in which insertion and deletion of elements are done at only one end, which is known as the top of the stack. Stack is called a last-in, first-out (LIFO) structure because the last element which is added to the stack is the first element which is deleted from the stack.


F
E
D
C
B
A

  • Every stack has a variable top associated with it used to store the address of the topmost element of the stack. It is this position from where the element will be added or deleted. There is another variable MAX, which is used to store the maximum number of elements that the stack can store.

A stack supports three basic operations: push, pop, and peep.

  1. The push operation adds an element to the top of the stack.
  2. The pop operation removes the element from the top of the stack.
  3. And the peep operation returns the value of the topmost element of the stack without deleting it.


  • An overflow occurs when we try to insert an element into a stack that is already full. Before inserting an element in data structures, we must check for overflow condition.
  •  An underflow condition occurs when we try to delete an element from a stack that is already empty. Before deleting an element from the stack, we must check for underflow conditions.

Applications of Stack
  • Reversing a list
  • Parentheses checker
  • Conversion of an infix expression into a postfix expression
  •  Evaluation of a postfix expression
  • Conversion of an infix expression into a prefix expression
  • Evaluation of a prefix expression
  • Recursion
  • Tower of Hanoi

No comments

Post a Comment