a stack that uses a number of queues c++ code example
Example: c++ stack and queue
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
void printStack(stack<int> custstack)
{
for(int i = 0; i < 3; i++)
{
int y = custstack.top();
cout << y << endl;
custstack.pop();
}
}
void printQueue(queue<int> custqueue)
{
for(int i = 0; i < 3; i++)
{
int y = custqueue.front();
cout << y << endl;
custqueue.pop();
}
}
int main ()
{
cout << "Stack:" << endl;
stack<int> MY_STACK;
MY_STACK.push(69);
MY_STACK.push(68);
MY_STACK.push(67);
printStack(MY_STACK);
cout << endl << "Switching to queue" << endl;
queue<int> MY_QUEUE;
MY_QUEUE.push(69);
MY_QUEUE.push(68);
MY_QUEUE.push(67);
printQueue(MY_QUEUE);
return 0;
}