554 views
1 votes
1 votes
STACK-EMPTY(S)
1     if S.top == 0
2     return TRUE
3     else return FALSE

PUSH(S , x)
1     S.top = S.top + 1
2     S[S.top] = x

POP(S)
1     if STACK-EMPTY(S)
2     error “underflow”
3     else S.top = S.top – 1
4     return S[S.top + 1]

illustrate the result of each operation in the sequence $PUSH(S,4), PUSH(S,1),PUSH(S,3),POP(S),PUSH(S,8),POP(S)$ on an initially empty stack $S$ stored in array $S[1...6]$

1 Answer

Related questions

1 votes
1 votes
1 answer
1
akash.dinkar12 asked Jun 28, 2019
2,494 views
Explain how to implement two stacks in one array $A[1...n]$ in such a way that neither stack overflows unless the total number of elements in both stacks together is $n$....
0 votes
0 votes
1 answer
2
akash.dinkar12 asked Jun 28, 2019
562 views
Rewrite ENQUEUE and DEQUEUE to detect underflow and overflow of a queue.
4 votes
4 votes
2 answers
4
akash.dinkar12 asked Jun 28, 2019
1,324 views
Show how to implement a stack using two queues. Analyze the running time of the stack operations.