What is the output?
#include <iostream>
#include <queue>
#include<stack>
using namespace std;
int main()
{
queue<int>
q; //declare an empty
queue
stack<int>
s; //declare an empty
stack
q.push(3); //How push works?
q.push(15);
q.push(27);
q.push(300);
while(!q.empty())
{
cout<<q.front()<<" "; //To see how a queue
stores data
q.pop();
//How pop works?
}
cout<<endl;
int arr[]={2,4,6,8,10,12,14,16,18,20};
for(int i=0; i<10; i++) //Push elements of array to a queue
q.push(arr[i]);
while(!q.empty())
{
cout<<q.front()<<" ";
q.pop();
}
cout<<endl;
for(i=0; i<10; i++) //Push elements
of array to a stack
s.push(arr[i]);
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
cout<<endl;
q.push(5);
q.push(10);
q.push(15);
q.pop();
q.push(20);
while(!q.empty())
{
cout<<q.front()<<" ";
q.pop();
}
cout<<endl;
s.push(5);
s.push(10);
s.push(15);
s.pop();
s.push(20);
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
cout<<endl;
system("pause");
return 0;
}