List

#include<iostream>
#include<list>
#include<algorithm>
using namespace std;
int main(void)
{
    list<int> c1,c2,c3,c4;
    list<int>::iterator
c1_Iter,c2_Iter,c3_Iter,w_Iter,f_Iter,l_Iter;
    c1.push_back(10),c1.push_back(10), c1.push_back(20),
c1.push_back(30);
    c2.push_back(‘u’), c2.push_back(‘a’), c2.push_back(60);
    c3.push_back(70), c3.push_back(80), c3.push_back(90);
    c4.push_back(‘i’), c4.push_back(‘j’), c4.push_back(‘k’);
    c1.merge(c2);
    for (c1_Iter = c1.begin();c1_澳门新萄京官方网站,Iter != c1.end();c1_Iter++)
cout<<*c1_Iter<<”  “;
    cout<<endl;
    c1.sort();
    for (c1_Iter = c1.begin();c1_Iter != c1.end();c1_Iter++)
cout<<*c1_Iter<<”  “;
    cout<<endl;
    c1.sort(greater<int>());
    for (c1_Iter = c1.begin();c1_Iter != c1.end();c1_Iter++)
cout<<*c1_Iter<<”  “;
    c1.unique();
    for (c1_Iter = c1.begin();c1_Iter != c1.end();c1_Iter++)
cout<<*c1_Iter<<”  “;
    cout<<endl;
    return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////

 

////////////////////////////////////////////////////////////////////////////////////////////////

 

#include<iostream>
#include<list>
#include<algorithm>
#include<iterator>
using namespace std;
void printlists(const list<int>& l1,const list<int>&l2)
{
    cout<<“List1: “;
    copy(l1.begin(),l1.end(),ostream_iterator<int>(cout,” “));
    cout<<“List2: “;
    copy(l2.begin(),l2.end(),ostream_iterator<int>(cout,” “));
    cout<<endl;
}
int main(void)
{
    list<int> list1,list2;   //create two empty lists
    for (int i=0;i<6;i++)    //fill both lists with elements
    {
        list1.push_back(i);
        list2.push_front(i);
    }
    printlists(list1,list2);
    //insert all elements of list1 beforethe first element  with value 3
of list2
    //find() returns an iterator to the first element with value 3
    list2.splice(find(list2.begin(),list2.end(),3),list1);   //
    printlists(list1,list2);     //move first element to the end
    list2.splice(list2.end(),list2,list2.begin());
    printlists(list1,list2);
    //sort second list,assign to the list1 and remove dupliceates
    list2.sort();
    list1 = list2;
    list2.unique();
    printlists(list1,list2);
    //merge both sorted lists into the first list
    list1.merge(list2);
    printlists(list1,list2);
    return 0;
}

网站地图xml地图