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. Kali Linux 命令集

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  2. Vim 中使用cscope

    使用cscope碰到的问题 1. E568: duplicate cscope database not added 根据提示,cscope数据库重复添加了,我使用的是vim7.2版本,而这个版本在已 ...

  3. UML状态图(转载)

    概述: 图表本身的名称,阐明该图的目的和其他细节.它描述了在一个系统中的一个组成部分不同的状态.状态是特定的一个系统的组件/对象. 状态图描述了一个状态机.我们阐明的状态机可以被定义为一台机器,它定义 ...

  4. ASP.NET中的事件处理

    一.ASP.NET中的事件主要支持3个主要的事件组:1.包含在asp.net生成页面时自动生成,我们使用这些事件建立页面(如page_load等)2.包含了用户与页面交互时发生的所有事件(这种最强大) ...

  5. MySQL 5.6 和 MariaDB-10.0 的性能比较测试

    MySQL 5.6 和 MariaDB-10.0 的性能比较测试 时间 2013-02-14 10:11:34  开源中国 原文  http://www.oschina.net/question/12 ...

  6. Swift 2.0 到底「新」在哪?

    [编者按]2015年6月,一年一度的苹果 WWDC 大会如期而至,在大会上苹果发布了 Swift 2.0,引入了很多新的特性,以帮助开发者更快.更简单地构建应用.本篇文章作者是 Maxime defa ...

  7. MySQL 5.1参考手册

    目录 前言 1. 一般信息 1.1. 关于本手册 1.2. 本手册采用的惯例 1.3. MySQL AB概述 1.4. MySQL数据库管理系统概述 1.4.1. MySQL的历史 1.4.2. My ...

  8. sessionID的本质

    SessionID的本质 一.客户端用cookie保存了sessionID 客户端用cookie保存了sessionID,当我们请求服务器的时候,会把这个sessionID一起发给服务器,服务器会到内 ...

  9. Linux - wxWidgets安装和编译HelloWorld

    安装参考http://codelite.org/LiteEditor/WxWidgets30Binaries#toc2 源 /etc/apt/source.list deb http://repos. ...

  10. HTML基本操作

    插入图片: 1.利用链接(静态) <img src="http://www.kmwzjs.com/useruploads/images/20101020_057600100825157 ...