1,480 views
1 votes
1 votes
If two stack is growing  two opposite end of array. Then which logic works and how?

1 Answer

Best answer
2 votes
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

Related questions

0 votes
0 votes
1 answer
1
Abhrajyoti00 asked Oct 29, 2022
741 views
Can there be “Stack Overflow” in Linked list Implementation of stack? If Yes, how?