Balancing of Symbols Infix To Postfix: Tower of Hanoi, Tree Traversals
Balancing of Symbols Infix To Postfix: Tower of Hanoi, Tree Traversals
1) Stack
It is a linear datastructure which follows a particular order in which the operations are
performed.The order may be LIFO(Last In First Out) or FILO(First IN Last Out).
--Basic Operations:
I.Push:
Add an item in the stack.If the stack is full, report stack overflow.
II. Pop:
Removes an item from the top of stack.Items are removed in the reversed order in
which they are pushed.If the stack is empty, then report “Stack Underflow”
III.Peek:
Returns the top element of stack.
IV.IsEmpty:
Returns true if stack is empty, else false.
Example:
Plates stacked over one another in a canteen. The plate at the top is removed at first,i.e
bottommost plate remains fot the longest period of time.
Applications of stack:
•Balancing of symbols
problem, histogram problem.
problem and sudoku solver
•Using array
A. Using Array:
Procedure:
structure stack:
maxsize :int
top : int
procedure initialize(stk:stack,size:int):
stk.maxsize← size
procedure push(stk:stack,x:item):
if(stk.top>stk.maxsize) :
Queue:
Array Implementation:
-works as FIFO basis(First In First Out ) or in first come first serve basis.
procedure:
structure queue:
final maxSize :int
front : int
[]items : is an array for queue
procedure initialize(qu:Queue,size:int)
maxSize=size
qu.items=new int array of size
front=-1 //initally empty