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;
templateclass MyStack {
// define two instance variables // by default, they are private queue
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
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
Get step-by-step solutions from verified subject matter experts
