advance

#include <bits/stdc++.h>
using namespace std;
int main()
{
    list <int> a = {1,2,3,4,5};
    list <int> b = {6,7,8,9,10};
    a.splice(a.end(),b,b.begin(),b.end());
    list <int> ::iterator i;
    for (i = a.begin();i != a.end(); i++) cout << *i << " " ;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
    list <int> a = {4,5,6};
    list <int> b = {1,2,3};
    list <int> ::iterator x;
    list <int> ::iterator y;
    x=b.begin();
    y=b.end();
    advance(x,+2);
    a.splice(a.begin(),b,x,y);
    list <int> ::iterator i;
    for (i = a.begin();i != a.end(); i++) cout << *i << " " ;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
    list <int> a = {4,5,6};
    list <int> b = {1,2,3};
    list <int> ::iterator x;
    list <int> ::iterator y;
    x=b.begin();
    y=b.end();
    advance(x,+2);
    a.splice(a.begin(),b,x,y);
    list <int> ::iterator i;
    for (i = a.begin();i != a.end(); i++) cout << *i << " " ;
    return 0;
}

 

posted @ 2024-01-05 19:48  hanxuyao  阅读(32)  评论(0)    收藏  举报