Question: C++: Implement the stubbed out functions in the MyQueue class using two stacks. The function specifications are shown below. The MyQueue class has 2 stacks

C++:

Implement the stubbed out functions in the MyQueue class using two stacks. The function specifications are shown below. The MyQueue class has 2 stacks as instance variables, which represent the inner state of the queue. Therefore, if an object has been dequeued from the queue it should not be in either stack. If an object is enqueued into the queue it should be present in at least one stack.

Methods to implement (specs also in the .h file):

#include  #include  using namespace std; 
template  class MyQueue { 

// these two stck are instance variables // by default, the access is private

 stack first; stack second; 

public:

 // return the value of the oldest member 

T front(){ // please implement this method

}

 // add value val to MyQueue 

void push(T val){ // please implement this method

}

// remove the oldest member from MyQueue

void pop(){ // please implement this method

} };

Use queueTest.cpp to test your implementation of the MyQueue class.

QueueTest.cpp:

#include #include "MyQueue.h" #include using namespace std; int main () { MyQueue names; /* Declare a MyQueue */ names.push ("Liz"); /* add values to the end of the MyQueue */ names.push ("John"); names.push ("Mike");

cout << "Serve the people in queue : " << endl; cout << names.front() << endl; names.pop(); cout << names.front() << endl; names.pop(); cout << names.front() << endl; names.pop(); return 0;

}

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!