Question: You are given the code skeleton for implementing a qpene using Stack (that is in tarn implemented using a Doubly Linked List) Complete the code

 You are given the code skeleton for implementing a qpene using

You are given the code skeleton for implementing a qpene using Stack (that is in tarn implemented using a Doubly Linked List) Complete the code for the enqucue), deqpoucO and isEmptyO functions of the Quese class. The code for the main function is also given to you. After you implement the above three functions, you can run your main function and capture screenshot. The queue size can range from 5 to 10 and the maximum vase for an element in the queue can be 50 As you can notice, there are two Stacks (stack1 and stack2) declared as private member variables in the Qucue class. You need to use these two Stacks for implementing the functionalities of a gaeuc. I suggest the following design (oyou are free to choose your own design provide a detailed explanation in your report if your design is different from mine). Use stackl to store the elements of the queue (with the invariant that the topmost element of stackl is the element at the front of the queue and the bottommost element of stackl is the element at the end of the queue) and use stack2 as an auxiliary data structure to implement the enqueue function, Since the topmost element of stackl is the element in the front of the queue, the dequeue function can be simply implemented as the result of a pop operation on stackl. It is the enqueue function that needs to be thought out in greater detail and implemented. I suggest the following idea for enqueue of an integer data First check if stackl is empty or not. If it is empty, simply push the 'data' to it and return froem the enqueue function. If stack1 is not empty to start with, then pop out all the elements of stackl and push each of them to stack2. After stackI gets empty, push the 'data' to it. Now, pop out all the elements of stack2 and push them back to stack!. As a result of this, the newly enqueued 'data' will be in the bottom of stack!. Submission (through Canvas): (1) Write a pscudo code of the enqucue function implemented for this problem Explain how the invariant that "the topmost element of stacki is the element at the froet of the queue and the botommost clement of stackl is the element at the end of the queue is maintained with each enqueue and dequeue operation (2) Discuss the theoretical time complexity of the enqueue and dequeue implementations (3) Include the complete C++ code of the (Doubly Linked List-based) Stack-based Queue implementation, including the main function (4) Show a screenshot of the execution of your implementation for a queue of size anywhere chosen from 5 to 10, with the maximum value of an element in the qucue being 50

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!