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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started