Create an array based queue in C++ with the number of elements and elements ente
ID: 3759671 • Letter: C
Question
Create an array based queue in C++ with the number of elements and elements entered from the keyboard and prints them and then finds the minimum, maximum, average of the stack elements.
Could you just modify this code for me. I'm not sure how to take the user input in a queue:
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> intQueue;
int number, i;
cout << "Enter some integers: "<<endl;
do
{
cin >> number;
intQueue.push(number);
} while (number);
cout << "The queue contains: ";
while (!intQueue.empty())
{
cout << " " << intQueue.front();
intQueue.pop();
}
}
Explanation / Answer
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> intQueue;
int number, i;
cout << "Enter some integers: "<<endl;
do
{
cin >> number;
intQueue.push(number);
} while (number);
cout << "The queue contains: ";
while (!intQueue.empty())
{
cout << " " << intQueue.front();
intQueue.pop();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.