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中 ...
随机推荐
- Linux权限赋予远程连接MySQL
1.mysql -u root -p (root)用户名 2.mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'r ...
- IP、TCP、DNS协议
·······················································IP协议························· 位于网络层,作用是把数据包传送 ...
- JavaSE 初学进度条JProgressBar
预备知识 创建进度条类后将其直接加入JFrame看看效果 public class JProgressBarDemo2 { public static void main(String args[]) ...
- 判断终端类型、微信的文章防盗链、h5页面跳转打开新的app、跳转到app市场
判断终端的类型.安卓.ios.微信.qq function GetMobelType() { var browser = { ...
- jquery的ajax及注意事项
1.引jquery包(jquery-1.8.0.min.js) <script type="text/javascript"> $(function () { //根据 ...
- Codeforces828 C. String Reconstruction
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 前端vue框架 脚手架
1.安装node.js最新版本2.cmd下输入 1.node -v得到版本号检测是否安装成功 版本号要在6.9以上 2.npm -v 版本号要在3.10以上3.安装脚手架 1.npm install ...
- js-实时获取键值码
<script> document.onkeydown=function(event){ console.log(event.keyCode) //在控制台打印 } </scr ...
- java 日志框架
1.java常用日志框架介绍: https://www.cnblogs.com/chenhongliang/p/5312517.html 2.java各类日志组件汇总: https://blog.cs ...
- iOS安装包瘦身的那些事儿
在我们提交安装包到App Store的时候,如果安装包过大,有可能会收到类似如下内容的一封邮件: 收到这封邮件的时候,意味着安装包在App Store上下载的时候,有的设备下载的安装包大小会超过100 ...