http://blog.csdn.net/bichenggui/article/details/4674900

list::splice实现list拼接的功能。将源list的内容部分或全部元素删除,拼插入到目的list。

函数有以下三种声明:

void splice ( iterator position, list<T,Allocator>& x );  //

void splice ( iterator position, list<T,Allocator>& x, iterator i );

void splice ( iterator position, list<T,Allocator>& x, iterator first, iterator last );

函数说明:在list间移动元素:

将x的元素移动到目的list的指定位置,高效的将他们插入到目的list并从x中删除。

目的list的大小会增加,增加的大小为插入元素的大小。x的大小相应的会减少同样的大小。

前两个函数不会涉及到元素的创建或销毁。第三个函数会。

指向被删除元素的迭代器会失效。

参数:

position

目的list的位置,用来标明 插入位置

x

源list、

first,last

x里需要被移动的元素的迭代器。区间为[first, last).

包含first指向的元素,不包含last指向的元素。

例子:

// splicing lists

#include <iostream>

#include <list>

#include <string>

#include <algorithm>

using namespace std;

int main ()

{

list<int> mylist1, mylist2;

list<int>::iterator it;

// set some initial values:

for (int i=1; i<=4; i++)

mylist1.push_back(i);      // mylist1: 1 2 3 4

for (int i=1; i<=3; i++)

mylist2.push_back(i*10);   // mylist2: 10 20 30

it = mylist1.begin();

++it;                         // points to 2

mylist1.splice (it, mylist2); // mylist1: 1 10 20 30 2 3 4

// mylist2 (empty)

// "it" still points to 2 (the 5th element)

mylist2.splice (mylist2.begin(),mylist1, it);

// mylist1: 1 10 20 30 3 4

// mylist2: 2

// "it" is now invalid.

it = mylist1.begin();

advance(it,3);                // "it" points now to 30

mylist1.splice ( mylist1.begin(), mylist1, it, mylist1.end());

// mylist1: 30 3 4 1 10 20

cout << "mylist1 contains:";

for (it=mylist1.begin(); it!=mylist1.end(); it++)

cout << " " << *it;

cout << "/nmylist2 contains:";

for (it=mylist2.begin(); it!=mylist2.end(); it++)

cout << " " << *it;

cout << endl;

list<string> dictionary, bword;

dictionary.push_back("any");

dictionary.push_back("angle");

dictionary.push_back("ajust");

dictionary.push_back("common");

dictionary.push_back("cannon");

dictionary.push_back("company");

bword.push_back("blue");

bword.push_back("banana");

bword.push_back("break");

list<string>::iterator its = dictionary.begin();

for (int i = 0; i < 3; i++)

its++;

dictionary.splice(its, bword);

copy(bword.begin(), bword.end(), ostream_iterator<string>(cout, "/n"));

return 0;

}

list::splice()函数详解的更多相关文章

  1. C++ list容器系列功能函数详解

    C++ list函数详解 首先说下eclipse工具下怎样debug:方法:你先要设置好断点,然后以Debug方式启动你的应用程序,不要用run的方式,当程序运行到你的断点位置时就会停住,也会提示你进 ...

  2. malloc 与 free函数详解<转载>

    malloc和free函数详解   本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: 1 ...

  3. NSSearchPathForDirectoriesInDomains函数详解

    NSSearchPathForDirectoriesInDomains函数详解     #import "NSString+FilePath.h" @implementation ...

  4. JavaScript正则表达式详解(二)JavaScript中正则表达式函数详解

    二.JavaScript中正则表达式函数详解(exec, test, match, replace, search, split) 1.使用正则表达式的方法去匹配查找字符串 1.1. exec方法详解 ...

  5. Linux C popen()函数详解

    表头文件 #include<stdio.h> 定义函数 FILE * popen( const char * command,const char * type); 函数说明 popen( ...

  6. kzalloc 函数详解(转载)

    用kzalloc申请内存的时候, 效果等同于先是用 kmalloc() 申请空间 , 然后用 memset() 来初始化 ,所有申请的元素都被初始化为 0. view plain /** * kzal ...

  7. Netsuite Formula > Oracle函数列表速查(PL/SQL单行函数和组函数详解).txt

    PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类: 单行函数 ...

  8. jQuery.attr() 函数详解

    一,jQuery.attr()  函数详解: http://www.365mini.com/page/jquery-attr.htm 二,jQuery函数attr()和prop()的区别: http: ...

  9. memset函数详解

    语言中memset函数详解(2011-11-16 21:11:02)转载▼标签: 杂谈 分类: 工具相关  功 能: 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的大 ...

随机推荐

  1. 【转载】在程序中动态改变static text控件的caption值

    方法1,给STATIC控件取个名字叫IDC_STATICTITLE 然后在ClassWizard中设定一个控件变量给它叫m_statictitle 然后用m_statictitle.SetWindow ...

  2. WPF使用RoutedCommand自定义命令

    主要代码如下所示: /// <summary> /// 声明并定义命令. /// </summary> RoutedCommand ClearCommand = new Rou ...

  3. JavaScript之工厂方式 构造函数方式 原型方式讲解

    一.工厂方式可以为一个对象,创建多个实例. var oCar = new Object; oCar.color = "red"; oCar.doors=4; oCar.mpg=23 ...

  4. 直面Javascript面试题算法思路

    一.字符串遍历类 1.获取符合条件的字符 思路:一般使用正则表达式会比遍历字符串简单.a=str.match(reg),a即为所得. 例子:a.判断字符串是否是这样组成的,第一个必须是字母,后面可以是 ...

  5. ZOJ 3555 Ice Climber(dp)

    晦涩的题意+各种傻逼害我调了那么久,实际上题目就是一个dp[i][j],dp[i][j]表示第i层第j个最少需要多少时间,当我们去更新dp[i][j]的时候,考虑的是从第i+1层的某一个dp[i+1] ...

  6. HTML5 webSQL

    https://www.ibm.com/developerworks/cn/web/1108_zhaifeng_websqldb/   <!DOCTYPE HTML> <html&g ...

  7. C# 获取windows特殊路径

    虽然是古老的问题,最近用到这个,查一下还不少东东呐 一.使用Environment.SpecialFolder 该方法最简单,直接使用即可,只是提供的特殊路径比较少. (1)使用方法:string p ...

  8. error LNK2019: 无法解析的外部符号 ___glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用 1>GEARS.obj : er

    转: http://blog.csdn.net/bill_ming/article/details/8150111 opengl的高级菜鸟问题 看了一本书<OpenGL三维图形系统开发与应用技术 ...

  9. [转]fedora启动telnet服务

    http://blog.chinaunix.net/uid-22996709-id-3056078.html 在win7上安装了SecurityCRT,登录VMWARE Fedora时候登录超时,检查 ...

  10. spring_150801_autowired_qualifier

    新建java project工程,建src.conf.test源码文件夹,导入相关包,需要spring的相关jar包和common-logging相关jar包 接口Service: package c ...