3. Implement a composite data structure; in this case you are to make a queue of
ID: 3714373 • Letter: 3
Question
3. Implement a composite data structure; in this case you are to make a queue of sets. We have beaten queue to death, but we never actually implemented sets (imagine that, what a coincidence). Implement a front end to allow the following menu driven interface: Menu create a new set and add it to the queue inserts a value X into the set at the front of C. the queue R. rotates the set in the front of the queue from to back S. searches the front set for a value X D. displays the content of all sets in the queue without lossExplanation / Answer
#include<bits/stdc++.h>
using namespace std;
void insert(queue<set<int > > &sq)
{
set<int> s={10,20,30,40,50,60};
sq.push(s);
}
void insert_front(queue<set<int > > &sq)
{
sq.front().insert(10);
}
void search(queue<set<int > > &sq,int value)
{
set<int> s=sq.front();
if(s.find(value)!=s.end())
cout<<value<<" found in set "<<endl;
else
cout<<"not found try again"<<endl;
}
void rotate(queue<set<int > > &sq)
{
stack<set <int> > s;
while(!sq.empty())
{
s.push(sq.front());
sq.pop();
}
while(!s.empty())
{
sq.push(s.top());
s.pop();
}
}
void display(queue<set<int > > &sq)
{
while(!sq.empty())
{
set<int> s=sq.front();
for(auto i=s.begin();i!=s.end();i++)
cout<<*i<<" ";
sq.pop();
}
}
int main()
{
queue<set <int > > sq;
insert(sq);
insert_front(sq);
rotate(sq);
search(sq,40);
display(sq);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.