Chapter 8
Queues and Priority Queues
Queues
while (!q.empty())
{
cout<<q.front()<<"
";
q.pop():
}
// remove the item at
the front of the queue
// by erasing the front
of the list
template <typename
T>
void miniQueue<T>::pop()
{
// if queue is
empty, throw underflowError
if (qlist.size()
== 0)
throw underflowError("miniQueue
pop(): empty queue");
// erase the front
qlist.pop_front();
}
cout << "Enter
an integer > 0 or 0 to quit: ";
cin >> value;
while (value != 0)
{
if (value % 2
== 0)
qList.push(value);
else
qDeque.push(value);
cout <<
"Enter an integer > 0 or 0 to quit: ";
cin >> value;
}
cout <<endl <<
"Even number: ";
while (!qList.empty())
{
cout <<
qList.front() << " ";
qList.pop();
}
cout <<endl <<endl;
cout<< "Odd numbers:
";
while (!qDeque.empty())
{
cout <<
qDeque.front() << " ";
qDeque.pop();
}
cout <<endl;
T& top();