Thursday, June 27, 2013

How can you use stack as an ADT?



Let S[N] be an array that is implemented as an stack of type T where ‘top’ points to the top element of the stack, then stack can be used as an ADT as follows:-
·         MakeEmpty(S): create an empty stack S of size N by setting top=-1.
·         IsEmpty(S): It returns true(1) if the stack S is empty, top==-1, otherwise, false(0).
·         IsFull(S):  It returns true(1) if the stack  S is full, top==N-1, otherwise, false(0).
·         push(S,item): It adds the ‘item’ at the top position of the stack S if the stack is not full.
·         pop(S): It removes the top element of the stack S is the stack is not empty.
·         traverse(S): Display all the elements of a stack S from top to bottom is the stack is not empty.
·         top(S): Return the top element of the stack S if the stack is not empty.

No comments:

Post a Comment