Write an algorithm of insertion (push) in Stack.

Push:

  • push is an operation of stack. which is used to insert data.
  • If the stack is full so the operation can not be performed  and return.
  • And if the space is available in stack so we increment in top and insert the value.

 

Algorithm:

Push(Stack,N,Top,value)
(1)[Start]
(2)[Check for Full]
If Top= N-1
Show “Stack is Full”
Return
Else
Top=Top+1
[End Of If Else step 2]
(3) Stack[Top]= Value
(4) [Return]

Leave a Reply

Your email address will not be published. Required fields are marked *