a) Write a series of C++ statements (ADT functions) that uses push()and to create a stack S1 capable of holding 10 elements and which actually stores the following, the top of the stack being theleftmost element:〈12,2,3,6,5〉
b) Then write a series of statements usingpop()to take those elements out from the stack and enqueue() them all in a queue Q capable of holding 15 elements. Show that queue.(front to be the leftmost element).
c) Finally create a second stack S2 in which you stores all the elements dequeued from the queue.
1) USING STL
#include<bits/stdc++.h>
using namespace std;
int main()
{
stack <int>s1,s2;
queue<int>q;
s1.push(5);
s1.push(6);
s1.push(3);
s1.push(2);
s1.push(12);
while(!s1.empty())
{
q.push(s1.top());
s1.pop();
}
while(!q.empty())
{
s2.push(q.front());
q.pop();
}
}
Get Answers For Free
Most questions answered within 1 hours.