list容器特有函数示例

1.

#include <iostream>
#include <list>
using namespace std;
int main(){
    list<int> a = {1,2,3};
    list<int> b = {4,5,6};
    list<int>::iterator i,j;
    j = a.end();
    advance(j,-1);
    b.splice(b.begin(),a,j);
    for(i = b.begin();i!=b.end();i++){
        cout<<*i<<" ";
    }
    return 0;
}

 

2.

#include <iostream>
#include <list>
using namespace std;
int main(){
    list<int> a = {1,2,3};
    list<int> b = {4,5,6};
    list<int>::iterator i,j;
    j = a.end();
    advance(j,-1);
    b.splice(b.begin(),a,j);
    for(i = b.begin();i!=b.end();i++){
        cout<<*i<<" ";
    }
    return 0;
}

 

3.

#include <iostream>
#include <list>
using namespace std;
int main(){
    list<int> a = {1,2,3,4,5};
    list<int> b = {6,7,8};
    list<int>::iterator i,j;
    i = a.begin();
    j = a.end();
    advance(i,1);
    advance(j,-1);
    b.splice(b.begin(),a,i,j);
    for(i = b.begin();i!=b.end();i++){
        cout<<*i<<" ";
    }
    return 0;
}

 

posted @ 2023-12-31 09:54  王一行(小号)  阅读(4)  评论(0编辑  收藏  举报