StacksDEFINITION1: Stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end.
DEFINITION2: Stack is a linear list in which insertions and deletions take place at the same end.
The end at which the operations are taking place is called top
The other end is called bottom
This is LIFO (Last-in-first-out) structure.
The insertion of element into stack is called push
The deletion of element from stack is called pop.
This situation will come when the stack is implemented using an array.
If an element is pushed into the stack when the size of the stack greater than or equal to maximum size of the array, then we say that the stack is overflowing.
If deletion operation is performed on the stack with no elements then the stack is said to be underflowing .This occurs in both types of implementations of stack.
Algorithm for push operation:
Push(key,top):(Array implementation of stack)
1)If(top>=maximum size of the stack)
i)Then print “Stack is overflowing”
Algorithm for pop operation:
1)print “The stack is underflowing”
Applications of stack :
2)Towers of Hanoi
3)Rearranging rail road cars
4)Rat in a maze.
I am writing this notes by referring to the following reference books. The students who are new to data structures are being advised to refer to “CLASSICAL DATA STRUCTURES” by SAMANTHA.
1) Data structures, Algorithms &Applications in c++ by SAHNI
2)classic data structures by SAMANTHA