Question: We want to implement two stacks (A and B) in a single array ARR . Write the following routines using pseudocode to achieve this: push
We want to implement two stacks (A and B) in a single array ARR . Write the following routines using pseudocode to achieve this:
push (stackID, val, ARR) StackID is either A or B. val is the value we want to insert. ARR is the array that hosts both the stacks (A and B). The above routine either inserts the val or returns false in case of an overflow.
pop (stackID, ARR) Returns an element from the stack referenced by stackID or returns false if the stack is empty.
Neither of the stack should overflow unless the total number of elements in both stacks together is n. Both push and pop should run in O(1) time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
