#include<iostream>
#include<list>
#include<iterator>
using namespace std;
int main()
{
list<int>ar;
list<int>:: iterator it;
ar.push_back(20);
ar.push_back(30);
ar.push_back(40);
ar.push_back(50);
ar.push_front(10);
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.reverse();
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.clear();
ar.push_back(100);
ar.push_back(200);
ar.push_back(300);
ar.push_back(400);
ar.push_back(500);
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.pop_back();
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.pop_front();
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl;
return 0;
}
#include<list>
#include<iterator>
using namespace std;
int main()
{
list<int>ar;
list<int>:: iterator it;
ar.push_back(20);
ar.push_back(30);
ar.push_back(40);
ar.push_back(50);
ar.push_front(10);
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.reverse();
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.clear();
ar.push_back(100);
ar.push_back(200);
ar.push_back(300);
ar.push_back(400);
ar.push_back(500);
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.pop_back();
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl << endl;
ar.pop_front();
for(it =ar.begin();it != ar.end();it++)
{
cout << *it << "\t";
}
cout << endl;
return 0;
}
Comments
Post a Comment