In C Using the standard library queue and stack classes impl
In C++
Using the standard library queue and stack classes implement the following data structures stack of queues queue of deques deque of stacks Test each of these structures by pushing 5 objects of 3 integers into them and corresponding output. You do not need to define any new classes; it is simply a matter of creating containers of containers of the appropriate type (std::stack, std::queue, and std::deque) using STL containers.Solution
#include <iostream>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <utility>
using namespace std;
int main()
{
std::queue<int> q1 ;
q1.push(1);
q1.push(2);
q1.push(3);
std::queue<int> q2 ;
q2.push(4);
q2.push(5);
q2.push(6);
std::queue<int> q3 ;
q3.push(7);
q3.push(8);
q3.push(9);
std::queue<int> q4 ;
q4.push(10);
q4.push(11);
q4.push(12);
std::queue<int> q5 ;
q5.push(13);
q5.push(14);
q5.push(15);
stack<queue<int> > sq;
sq.push(q1);
sq.push(q2);
sq.push(q3);
sq.push(q4);
sq.push(q5);
std::queue<int> testQ =sq.top();
for(int i=0;i<3;i++)
{
int temp=testQ.front(); //The answer should display the elements of top of stack, ie q5.
testQ.pop();
cout<<temp<<endl;
}
//-------------------------------------------------------------------------------------------
//Queue of deques
std::queue<deque<int> > qd;
std::deque<int> dq1 ;
dq1.push_front(1);
dq1.push_front(2);
dq1.push_front(3);
std::deque<int> dq2 ;
dq2.push_front(4);
dq2.push_front(5);
dq2.push_front(6);
std::deque<int> dq3 ;
dq3.push_front(7);
dq3.push_front(8);
dq3.push_front(9);
std::deque<int> dq4 ;
dq4.push_front(10);
dq4.push_front(11);
dq4.push_front(12);
std::deque<int> dq5 ;
dq5.push_front(13);
dq5.push_front(14);
dq5.push_front(15);
qd.push(dq1);
qd.push(dq2);
qd.push(dq3);
qd.push(dq4);
qd.push(dq5);
std::deque<int> testDQ =qd.front();
for(int i=0;i<3;i++)
{
int temp=testDQ.front(); //The answer should display the elements of front of queue,ie of q1.
testDQ.pop_front();
cout<<temp<<endl;
}
//-------------------------------------------------------------------------------------------
deque<stack<int> > ds;
std::stack<int> s1 ;
s1.push(1);
s1.push(2);
s1.push(3);
std::stack<int> s2 ;
s2.push(4);
s2.push(5);
s2.push(6);
std::stack<int> s3 ;
s3.push(7);
s3.push(8);
s3.push(9);
std::stack<int> s4 ;
s4.push(10);
s4.push(11);
s4.push(12);
std::stack<int> s5 ;
s5.push(13);
s5.push(14);
s5.push(15);
ds.push_back(s1);
ds.push_back(s2);
ds.push_back(s3);
ds.push_back(s4);
ds.push_back(s5);
std::stack<int> testDS =ds.front();
for(int i=0;i<3;i++)
{
int temp=testDS.top(); //The answer should display the elements of front of deque,ie of s1.
testDS.pop();
cout<<temp<<endl;
}
return 0;
}


