operations on stack stack supports three basic operationspushpopand peek the push operation adds an element to the top of the stack and the pop operation removes the element from the top of the stack the peek operation returns the value of the topmost element of the stack push operation the push operation is used to insert an element into the stack the new element is added at the topmost position of the stack howeverbefore inserting the valuewe must first check if top=max- because if that is the casethen the stack is full and no more insertions can be done if an attempt is made to insert value in stack that is already fullan overflow message is printed consider the stack given in fig top figure stack to insert an element with value we first check if top=max- if the condition is falsethen we increment the value of top and store the new element at the position given by stack[topthusthe updated stack becomes as shown in fig top figure stack after insertion figure shows the algorithm to insert an element in stack in step we first check for the overflow condition in step top is incremented so that it points to the next location in the array in step the value is stored in the stack at the location pointed by top step if top max- print "overflowgoto step [end of ifstep set top top step set stack[topvalue step end pop operation the pop operation is used to delete the topmost element from the stack howeverbefore deleting the valuewe must first check if figure algorithm to insert an element in stack top=null because if that is the casethen it means the stack is empty and no more deletions can be done if an attempt is made to delete value from stack that is already emptyan underflow message is printed consider the stack given in fig top figure stack to delete the topmost elementwe first check if top=null if the condition is falsethen we decrement the value pointed by top thusthe updated stack becomes as shown in fig step if top null print "underflowgoto step [end of ifstep set val stack[topstep set top top step end figure algorithm to delete an element from stack top figure stack after deletion figure shows the algorithm to delete an element from stack in step we first check for the underflow condition in step the value of the location in the stack pointed by top is stored in val in step top is decremented