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中 ...
随机推荐
- 配置MQTT服务器
第一步:下载一个Xshell 链接:https://pan.baidu.com/s/16oDa5aPw3G6RIQSwaV8vqw 提取码:zsb4 打开Xshell 前往MQTT服务器软件下载地址: ...
- 100-days: fourteen
Title: Face mask craze(面膜热) creates Korean(韩国) (a) billionaire with Goldman(高盛集团) backing face mask ...
- [剑指Offer]38-字符串的全排列
链接 https://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7?tpId=13&tqId=11180&tPa ...
- 9.22 keep studying
项目要换用element组件了. element [http://element.eleme.io/1.4/#/zh-CN]是饿了么前端出品的一套基于Vue2.0的组件库,今天看了一下,确实简单好看. ...
- 890. Find and Replace Pattern找出匹配形式的单词
[抄题]: You have a list of words and a pattern, and you want to know which words in words matches the ...
- [leetcode]244. Shortest Word Distance II最短单词距离(允许连环call)
Design a class which receives a list of words in the constructor, and implements a method that takes ...
- node.js中使用yargs来处理命令行参数
yargs库能够方便的处理命令行参数. 一.安装 yargs npm install yargs --save 二.读取命令行参数 const yargs = require('yargs'); le ...
- springboot 使用JPA自动生成Entity实体类的方法
1. 2. 3.添加数据库 4. 5. 6. 7.点击OK完成. 8.去掉红色波浪线方法. 9.配置数据源 完成!
- CSP里的xss
无CSP保护下的xss 1.直接嵌入型 <img src="192.168.81.137:80/xss.php?a=[cookie]"> 过滤较少时,优先考虑.触发方式 ...
- python运算符优先级
下面这个表给出Python的运算符优先级,从最低的优先级(最松散地结合)到最高的优先级(最紧密地结合).这意味着在一个表达式中,Python会首先计算表中较下面的运算符,然后在计算列在表上部的运算符. ...