Tuesday 15 September 2020

Stack Operations

 Stack Operations


push() − Pushing (storing) an element on the stack.


pop() − Removing (accessing) an element from the stack.


peek() or Top() − get the top data element of the stack, without removing it.


PEEP() To find nth element from stack.


PEEP(Stack_s1, TOP, i) 

 //Check for Stack Underflow 

If(TOP-i+1 < 0) then 

 Write (‘Stack Underflow For PEEP’) 

 Return 

  //Return ith element from top of stack 

Return Stack_s1 [Top – i + 1] 


isFull() − check if stack is full.


isEmpty() − check if stack is empty.


push(), pop(), isEmpty() and peek() etc. all take O(1) time. We do not run any loop in any of these operations.

No comments:

Post a Comment