Take user input and insert the data at the respective position in the sorted 1) stack 2) queue and 3) linked list.
#include <iostream>
#include <stack>
#include <queue>
#include <list>
using namespace std;
int main()
{
int x;
cout<<"Enter an integer : ";
cin>>x;
//stack
stack<int> s;
s.push(x);
cout<<"\nInteger stored in stack: "<<x;
//queue
queue<int> q;
q.push(x);
cout<<"\nInteger stored in queue: "<<x;
//linkedlist
list<int> l;
l.push_front(x);
cout<<"\nInteger stored in linked list: "<<x;
return 0;
}
Comments
Leave a comment