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;
templateclass MyQueue {
// these two stck are instance variables // by default, the access is private
stackfirst; 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
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
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