Question: C++: Implement the stubbed out functions in the MyStack class using two queues. The MyStack class has 2 queues as instance variables, which represent the

C++:

Implement the stubbed out functions in the MyStack class using two queues. The MyStack class has 2 queues as instance variables, which represent the inner state of the stack. So, like with MyQueue, if an item is pushed onto the stack, it should be in at least one queue, and if an object is popped, it should not be in either queue.

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

// define two instance variables // by default, they are private queue first; queue second;

public:

// return the latest value of MyStack 

T top(){

// please implement this method

}

 // add value val to MyStack 
 void push(T val){ 

// please implement this method

}

// remove the oldest value from MyStack

void pop(){

// please implement this method

};

}

Use stackTest.cpp to test your implementation of the MyStack class.

stackTest.cpp:

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

cout << "Serve the people in stack: " << endl; cout << names.top() << endl; names.pop(); cout << names.top() << endl; names.pop(); cout << names.top() << 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!