Thursday, June 27, 2013

Write the algorithm to push the item onto the stack.



Let S[N] be the stack with size N of type T. ‘top’ is an integer variable that indicate the top of the stack. Then the algorithm to push the item onto the stack is as follows:
1.   Start
2.   Check stack overflow
If(top==N-1) THEN
Print “stack is full” and exit, else
3.   Increment ‘top’ by 1
++top;
4.   Add an ‘item’ into the top position
S[top]= item;
5.   Exit

No comments:

Post a Comment