Experiment 12
Experiment 12
Theory:
STL allows for customization through the use of user-defined types, enabling
developers to create specialized containers, iterators, and algorithms. By
overloading operators and implementing required interfaces, custom types can
seamlessly integrate with the STL.
Output:
Program: Output:
#include<iostream>
#include<conio.h>
#include<deque>
using namespace std;
void display(deque <double> &);
int main(){
deque <double> d;
d.push_front(2.2);
d.push_front(3.5);
d.push_back(1.1);
cout<<"\nDeque elements
after insertion are as follows :";
display(d);
d.pop_front();
cout<<"\nDeque elements
after pop_front() are as follows :";
display(d);
d[1]=3.3;
cout<<"\nDeque elements
after subscript insertion using [] are
as follows :";
display(d);
getch();
return 0;
}
void display(deque <double> & d1){
for(int i=0;i<d1.size();i++)
{
cout<<" "<<d1[i];
}
}
Program: {
#include<iostream> s.push(i);
#include<conio.h> cout<<s.top()<<" ";
#include<vector> }
#include<list> }
#include<deque>
#include<stack> template<class T>
using namespace std; void popelement(T & s)
template<class T> void {
pushelement(T & s); while(!s.empty())
template<class T> void popelement(T {
& s); cout<<s.top()<<" ";
int main(){ s.pop();
stack <int> dequestack; }
stack <int,vector<int> > }
vectorstack;
stack <int,list<int> > liststack; Output:
cout<<"\npushing elements
onto dequestack : ";
pushelement(dequestack);
cout<<"\npushing elements
onto vectorstack : ";
pushelement(vectorstack);
cout<<"\npushing elements
onto liststack : ";
pushelement(liststack);
cout<<"\
n------------------------------------------------"
;
cout<<"\npopping element from
dequestack : ";
popelement(dequestack);
cout<<"\npopping element from
vectorstack : ";
popelement(vectorstack);
cout<<"\npopping element from
liststack : ";
popelement(liststack);
getch();
return 0;
}
template<class T>
void pushelement(T & s){
for(int i=0;i<10;i++)
Program: Output:
#include<iostream>
#include<conio.h>
#include<queue>
using namespace std;
int main(){
queue <double> q;
q.push(1.1);
q.push(2.2);
q.push(3.3);
cout<<"\nPopping elements from
queue : ";
while(!q.empty()){
cout<<q.front()<<" ";
q.pop();
}
getch();
return 0;
}
Program: Output:
Conclusion: