Question: In this homework assignment, you have to implement the twoStacks class that represent two stacks and template your class. Implementation of twoStacks should use only
In this homework assignment, you have to implement the twoStacks class that represent two stacks and template your class. Implementation of twoStacks should use only one array, i.e., both stacks should use the same array for storing elements.
Following functions must be supported by twoStacks.
void push1(T x) > pushes x to first stack
void push2(T x) > pushes x to second stack
void pop1() > pops an element from first stack
void pop2() > pops an element from second stack
T top1() > return the top of stack1
T top2() > return the top of stack1
int size1() > return the size of stack1
int size2() > return the size of stack2
Implementation of twoStack should be space efficient, meaning the total number of elements from both stacks can add up to the size of the array. For instance, if you define an array of size 10, then it should be possible for stack 1 to have 1 element and stack 2 to have 9 elements, or stack 1 to have 6 elements and stack 2 to have 4 elements). write code in C++. dont use any online webistes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
