Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions