list源码1(参考STL源码--侯捷):list节点、迭代器、数据结构

list源码2(参考STL源码--侯捷):constructor、push_back、insert

list源码3(参考STL源码--侯捷):push_front、push_back、erase、pop_front、pop_back、clear、remove、unique

list源码4(参考STL源码--侯捷):transfer、splice、merge、reverse、sort

push_front()

//插入一个节点,作为头结点
void push_front(const T& x){insert(begin(),x);}

push_back()

//插入一个节点,作为尾节点
void push_back(const T &x){insert(end(),x);}

earse

//移除迭代器position所指节点
iterator erase(iterator position){
link_type next_node=link_type(position.node->next);
link_type prev_node=link_type(position.node->prev);
prev_node->next=next_node;
next_node->prev=prev_node;
destory_node(position.node);
return iterator(next_node);
}

pop_front

//移除头结点
void pop_front(){erase(begin());}

pop_back

//移除尾节点
void pop_back(){
iterator temp=end();
erase(--temp);
}

clear

//清除所有节点
template<class T,class Alloc>
void list<T,Alloc>::clear(){
link_type cur=(link_type)node->next;//begin()
while(cur!=node){ //遍历每一个节点
link_type temp=cur;
cur=(link_type)cur->next;
destory_node(temp);
}
//恢复node原始状态
node->next=node;
node->prev=node;
}

remove 

//将数值为value的数据移除
template<class T,class Alloc>
void list<T,Alloc>::remove(const T& value){
iterator first=begin();
iterator last=end();
while(first!=last){ //遍历整个list
iterator next=first;
++next;
if(*first==value) earse(first); //移除
first=next;
}
}

unique

//移除数值相同的连续元素,注意:“连续相同的元素才会被移除剩下一个”
template<class T,class Alloc>
void list<T,Alloc>::unique(){
iterator first=begin();
iterator last=end();
if(first==last) return; //空链表
iterator next=first;
while(++next!=last){
if(*first==*next) erase(next); //相同擦除该元素
else first=next;
next=first; //修正范围
}
}

list源码3(参考STL源码--侯捷):push_front、push_back、erase、pop_front、pop_back、clear、remove、unique的更多相关文章

  1. list源码4(参考STL源码--侯捷):transfer、splice、merge、reverse、sort

    list源码1(参考STL源码--侯捷):list节点.迭代器.数据结构 list源码2(参考STL源码--侯捷):constructor.push_back.insert list源码3(参考STL ...

  2. list源码1(参考STL源码--侯捷):list节点、迭代器、数据结构

    list源码1(参考STL源码--侯捷):list节点.迭代器.数据结构 list源码2(参考STL源码--侯捷):constructor.push_back.insert list源码3(参考STL ...

  3. list源码2(参考STL源码--侯捷):constructor、push_back、insert

    list源码1(参考STL源码--侯捷):list节点.迭代器.数据结构 list源码2(参考STL源码--侯捷):constructor.push_back.insert list源码3(参考STL ...

  4. vector源码3(参考STL源码--侯捷):pop_back、erase、clear、insert

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷):空间分配.push_back vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 v ...

  5. vector源码2(参考STL源码--侯捷):空间分配、push_back

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...

  6. vector源码1(参考STL源码--侯捷):源码

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...

  7. vector源码(参考STL源码--侯捷):空间分配导致迭代器失效

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...

  8. STL 源码分析 (SGI版本, 侯捷著)

    前言 源码之前,了无秘密 algorithm的重要性 效率的重要性 采用Cygnus C++ 2.91 for windows cygwin-b20.1-full2.exe 下载地址:http://d ...

  9. STL源码阅读-functor与adapter

    为什么要用仿函数 函数指针不灵活,难以与STL其他组件配合使用 Adapter 将一个class的接口转换为另一个class的接口,使原本因接口不兼容而不能合作的classes,可以一起运作 STL中 ...

随机推荐

  1. Rifidi

    简介 Rifidi是RFID软件公司Pramari推出了一款开源中间件平台,其主页是:http://www.rifidi.org/ 其分为Edge Server, Workbench, Prototy ...

  2. FortiGate数据流分析 debug flow

    1.工具说明 在防火墙部署中,经常会遇到防火墙接收到了数据包,但并未进行转发.可以通过diagnose debug flow 命令来对数据包的处理过程进行跟踪,可以清晰查看数据包再各个功能模块内的处理 ...

  3. [leetcode]19. Remove Nth Node From End of List删除链表倒数第N个节点

    Given a linked list, remove the n-th node from the end of list and return its head. Example: Given l ...

  4. 20172325 2018-2019-2 《Java程序设计》第六周学习总结

    20172325 2018-2019-2 <Java程序设计>第六周学习总结 教材学习内容总结 本周学习第十章--树 1.什么是树 (1)树是一种数据结构,与之前学过的栈.队列和列表这些线 ...

  5. win10自带输入法的标点符号切换

    快捷键是ctrl+句号 然后开启设置,把中文也用英文标点也选上.

  6. E: Sub-process /usr/bin/dpkg returned an error code

    E: Sub-process /usr/bin/dpkg returned an error code (1)错误解决 在用apt-get安装软件时出现了类似于install-info: No dir ...

  7. 学习pyyaml

    网上查了一圈,觉得较好的yaml教程有: YAML 语言教程 :http://www.ruanyifeng.com/blog/2016/07/yaml.html. 另外,在github的pyyaml库 ...

  8. oracle删除dbf导致的oracle工具不能正常使用

    1.使用cmd命令登录Oracle:sqlplus / as sysdba;就可以,中间两个空格.2.删除了dbf导致Oracle工具不能正常使用解决办法(oracle initialization ...

  9. 地址栏的路由输入不匹配时候,设置默认跳转页面(redirect)

    如果输入正确的路由,就会显示正确的页面. 如果输入错误的路由 ,则可以配置跳转到指定的页面. { redirect:"/', path:"*" ; }

  10. thinkphp 5.1 同时选中多个文件上传

    <form id="ajaxform" enctype="multipart/form-data" class="form"> ...