list源码3(参考STL源码--侯捷):push_front、push_back、erase、pop_front、pop_back、clear、remove、unique
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的更多相关文章
- list源码4(参考STL源码--侯捷):transfer、splice、merge、reverse、sort
list源码1(参考STL源码--侯捷):list节点.迭代器.数据结构 list源码2(参考STL源码--侯捷):constructor.push_back.insert list源码3(参考STL ...
- list源码1(参考STL源码--侯捷):list节点、迭代器、数据结构
list源码1(参考STL源码--侯捷):list节点.迭代器.数据结构 list源码2(参考STL源码--侯捷):constructor.push_back.insert list源码3(参考STL ...
- list源码2(参考STL源码--侯捷):constructor、push_back、insert
list源码1(参考STL源码--侯捷):list节点.迭代器.数据结构 list源码2(参考STL源码--侯捷):constructor.push_back.insert list源码3(参考STL ...
- vector源码3(参考STL源码--侯捷):pop_back、erase、clear、insert
vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷):空间分配.push_back vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 v ...
- vector源码2(参考STL源码--侯捷):空间分配、push_back
vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...
- vector源码1(参考STL源码--侯捷):源码
vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...
- vector源码(参考STL源码--侯捷):空间分配导致迭代器失效
vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...
- STL 源码分析 (SGI版本, 侯捷著)
前言 源码之前,了无秘密 algorithm的重要性 效率的重要性 采用Cygnus C++ 2.91 for windows cygwin-b20.1-full2.exe 下载地址:http://d ...
- STL源码阅读-functor与adapter
为什么要用仿函数 函数指针不灵活,难以与STL其他组件配合使用 Adapter 将一个class的接口转换为另一个class的接口,使原本因接口不兼容而不能合作的classes,可以一起运作 STL中 ...
随机推荐
- 37 【kubernetes】搭建dashboard
官方的操作步骤是:https://github.com/kubernetes/dashboard 我自己的步骤是: 1,下载yaml文件 wget https://raw.githubusercont ...
- android的事件分发传递机制
事件的分发与传递最重要的三个处理方法是 dispatchTouchEvent onInterceptTouchEvent onTouchEvent 综合来说事件的 传递是由外层向里层传递,而处理是从里 ...
- centos 7 添加中文输入法
中文输入法
- 选择困难症的福音——团队Scrum冲刺阶段-Day5(补发 那天csshow)
选择困难症的福音--团队Scrum冲刺阶段-Day 5 今日进展 编写提问部分 游戏分类的界面 将之前错误的图标改正 关于我们的俄罗斯方块,今天有了新的进展 NextBlockView(定义了下一个方 ...
- python任意进制转换
python任意进制转换 import string def module_n_converter(q, s, base=None): """ 将自然数按照给定的字符串转 ...
- oracle 为什么没有权限的用户也可以用sysdba登录
我随便创建了一个用户,create user lisi identified by lisi; 当我用sqlplus登录的时候: cmd -> sqlplus lisi/lisi 进不去 ...
- 无线网卡连接网络后共享给本地有线网卡使用(Win10)
无线网卡连接网络后共享给本地有线网卡使用(Win10) 1. 本文主要目的是介绍地有线网卡共享无线网卡的Wifi信号,该应用场景如下: 当在只有wifi环境下,同时有两台电脑A和B, A为笔记本: ...
- kbmmw 5.07 正式发布
来了来了 5.07.00 Dec 9 2018 Important notes (changes that may break existing code) === ...
- Kotlin 开篇
Kotlin 是一个基于 JVM 的新的编程语言,由 JetBrains 开发官网地址:http://kotlinlang.org.JetBrains,作为目前广受欢迎的 Java IDE Intel ...
- Nginx+Django搭建
本机环境介绍 虚拟机操作系统版本如下 [root@node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) IP地址 ...