Question: Define a class DoubleStack which implements two stacks of objects of type Object using a single shared array, so that the push and pop operations

 Define a class DoubleStack which implements two stacks of objects of

Define a class DoubleStack which implements two stacks of objects of type Object using a single shared array, so that the push and pop operations specify which of the two stacks is involved in the operation (as described below). (a) Specify necessary instance variables and write a constructor DoubleStack(int n) that takes integer n and creates an empty DoubleStack object with the shared array with room for n elements (2 pt); b) Write methods "boolean push(int i, Object o)" and "Object pop(int i) which take the stack number i (0 or 1) as the first argument and perform the specified operation on the corresponding stack. Your "push routine returns "true" if the object has been pushed and "false" if there is an overflow (no room to insert the object). You should not declare an overflow unless the whole array is completely full. Your "pop" returns "null" if the corresponding stack is empty. (6 pts -- 3 pts for each of the two methods)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!