2,552 views

1 Answer

Best answer
2 2 votes

As much i understand from  question two stack implementation using single array.

Array[1........n]

Stack1 with top1=0 [when element added in stack1 top1++] push increment and pop decrement in top1.

stack2 with top2=n+1[when element added in stack2 top2--]push decrement and pop increment in top2(may be bug as A[n+1] so we set top2 acc]

if array full top1 +1 =top2

if array empty top1=n-top2+1

• edited by
Position:
Show:

Related questions

9 9 votes
2 2 answers
435
435 views
GO Classes asked Jul 27
435 views
Given a stack $S$ with $5$ elements from top to bottom as:$2, 4, 6, 8, 10$and an empty queue $Q$.First, remove the elements one by one from $S$ and insert them into $Q$.T...
7 7 votes
1 1 answer
509
509 views
GO Classes asked Jul 27
509 views
Which of the following statements are true?$\text{S1.}$ Stack operations $\texttt{push}$, $\texttt{pop}$, and $\texttt{isEmpty}$ can be worst-case $O(1)$ for a linked-lis...
7 7 votes
1 1 answer
323
323 views
GO Classes asked Jul 10
323 views
Assume there are $n$ elements in the data structure. Consider the following statements:$\text{S1}:$ A stack can be implemented using a linked list such that each individu...
6 6 votes
3 3 answers
333
333 views
GO Classes asked Jul 8
333 views
Suppose an intermixed sequence of stack push and pop operations is performed. The push operations push the integers $0$ through $9$ in order. The pop operations print the...