797 views
2 2 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

Position:
Show:

Related questions

1 1 vote
1 1 answer
3.5k
3.5k views
akash.dinkar12 asked Jun 28, 2019
3,490 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 0 votes
1 1 answer
778
778 views
akash.dinkar12 asked Jun 28, 2019
778 views
Rewrite ENQUEUE and DEQUEUE to detect underflow and overflow of a queue.
0 0 votes
1 1 answer
675
675 views
akash.dinkar12 asked Jun 28, 2019
675 views
ENQUEUE(Q, x) 1 Q[Q.tail] = x 2 if Q.tail == Q.length 3 Q.tail = 1 4 else Q.tail = Q.tail + 1 DEQUEUE(Q) 1 x = Q[Q.head] 2 if Q.head == Q.length 3 Q.head = 1 4 else Q.hea...
4 4 votes
2 2 answers
1.7k
1.7k views
akash.dinkar12 asked Jun 28, 2019
1,722 views
Show how to implement a stack using two queues. Analyze the running time of the stack operations.