Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Build a queue out of two completely separate stacks, 51 and S2. Enqueue operations happen by pushing the data on to stack 1 Dequeue operations
Build a queue out of two completely separate stacks, 51 and S2. Enqueue operations happen by pushing the data on to stack 1 Dequeue operations are completed with a pop from stack 2. Obviously you wil have to find some way to get the input stack information over to the output stack. Your job is to figure out how and when to do that, using only push and pop operations Write a class TwoStackQueue that provides the Queue ADT (as specifled in MyQueue interface provided in the ile MyQueue.java) using two stacks. Your dass should explicily implement the interface provided above. Since the interface is generic, your class should be as well. Provide all methods specified in the interface. Your class should nat use any additional memory to store the data in thequeue except for the two stacks. For your stacks, use the MyStack class that you implemented in the first problem. e Write a tester class with a main method to demonstrate that your TwoStackQueue works correctly (by enqueueing a number of objects and then dequeueing and printing thern in the correct order). Call your tester class Problem2java. You can find a sample tester class in the file TwoStackQueueTester. It is similar to the one that we will use to grade your submission. Your tester should try different examples than the ones from this sample. In a file called Problem2.txt, discuss the big-O running time of the enqueue and dequeue operation for your queue implementatian. (Hint one of these operations should a ways be O(1) the ather can vary a bit, but shouldn't always be O(N)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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