1#include <iostream>
2#include <stack>
3#include <queue>
4using namespace std;
5
6void printStack(stack<int> custstack)
7{
8 for(int i = 0; i < 3; i++)
9 {
10 int y = custstack.top();
11 cout << y << endl;
12 custstack.pop();
13 }
14}
15
16void printQueue(queue<int> custqueue)
17{
18 for(int i = 0; i < 3; i++)
19 {
20 int y = custqueue.front();
21 cout << y << endl;
22 custqueue.pop();
23 }
24}
25
26int main ()
27{
28 cout << "Stack:" << endl;
29 // this stack stacks three elements one by one and displays each element before its removal
30 stack<int> MY_STACK; // define stack and initialize to 3 elements
31 MY_STACK.push(69); // last element popped / displayed
32 MY_STACK.push(68); // second element popped / displayed
33 MY_STACK.push(67); // third popped/displayed
34 printStack(MY_STACK);
35
36 cout << endl << "Switching to queue" << endl;
37
38 queue<int> MY_QUEUE;
39 MY_QUEUE.push(69); // first out
40 MY_QUEUE.push(68); // second out
41 MY_QUEUE.push(67); // third out
42 printQueue(MY_QUEUE);
43 return 0;
44}