#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int array[] = {9,8,7,9, 6, 5,1,2,3,4,1,2,5};
//Initialize
list<int> l(array, array + sizeof(array)/sizeof(array[0]));
list<int> l2;
l2.assign(array, array + sizeof(array)/sizeof(array[0]));
list<int>::iterator it = l.end();
vector<int> v(3,30);
//Insert
l.insert(it, 10);
l.insert(it, 2, 20);
l.insert(it, v.begin(), v.end());
l2.push_back(10);
//Delete
l.erase(l.begin());
l2.erase(l2.begin(), l2.begin()++);
//Search
list<int>::iterator it1 = find(l.begin(), l.end(), 7);
cout<<"Found: "<<*it1<<endl;
//Traverse
for(list<int>::iterator it = l.begin(); it != l.end(); it++)
cout<<*it<<" ";
cout<<endl;
for(list<int>::iterator it = l2.begin(); it != l2.end(); it++)
cout<<*it<<" ";
cout<<endl;
//Clear
l.clear();
}
No comments:
Post a Comment