1: //queue02.cpp
3: #include <iostream>
4: #include <queue>
5: #include <deque>
6: #include <list>
7: using namespace std;
9: int main()
10: {
11: cout << "\nThis program illustrates the creation of a queue using "
12: "values from a deque\n(when the underlying container is the "
13: "default one, namely a deque), and from\na list, when the "
14: "underlying container is a list.";
15: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
17: int a1[] = {1, 2, 3, 4};
18: deque<int> d(a1, a1+4);
19: queue<int> q1(d);
20: cout << "\nThe queue q1 is created from a deque of 4 values.";
21: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
23: cout << "\nHere are the values of q1, in \"FIFO\" order:\n";
24: //This is the proper way to access the elements of a queue:
25: while(!q1.empty())
26: {
27: cout << "Popping: ";
28: cout << q1.front() << "\n";
29: q1.pop();
30: }
31: cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
33: int a2[] = {6, 9, 8, 10, 5, 7};
34: list<int> lst(a2, a2+6);
35: queue<int, list<int>> q2(lst);
36: cout << "\nThe queue q2 is created from a list of 6 values.";
37: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
39: cout << "\nHere are the values of q2, in \"FIFO\" order:\n";
40: while(!q2.empty())
41: {
42: cout << "Popping: ";
43: cout << q2.front() << "\n";
44: q2.pop();
45: }
46: cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
47: }