当前位置:网站首页>Article title
Article title
2022-06-09 05:17:00 【wolf_ break】
list,stl Basic container linked list in , Specifically, it is a circular two-way linked list .
Realization
node
As a linked list , Let's first look at the important basic elements - node . A node node The composition is as follows :
- prev: Front node
- next: Post node
- data : data
iterator
A pointer is required inside the iterator (list_type *node) Point to the corresponding node , And it can realize some basic operations of iterators .
- ++
self& operator++(){ // ++iter;
node = node->next;
return *this;
}
self& operator++(){ // iter++;
self tmp = *this;
++*this;
return tmp;
}- ->
- *
self & opearator *()const{
return node->data;
}The iterator basic operation passes through the node pointer node To achieve .
list
For linked lists , Only one node pointer is required pNode To achieve a two-way circular linked list . The node pointer points to the trailing blank node .
For related operations of linked lists , Analyze one by one
begin : pNode->next
end : pNode
empty : pNode->next == pNode
size : distance(begin(), end(), result
front : *begin(), Using an iterator * operation
- back : *end(), ditto
Next, consider push,pop,insert,erase Wait for the operation
insert
notes :stl all insert All operations are inserted before the current position
insert(iterator pos, const T &x); stay pos Before the position Insert elements x, Involving old and new nodes next and prev Pointer replacement, etc , No specific analysis , The interior is also very simple .
Note here : This function returns the iterator of the new node , also pos The position of the iterator does not change .push_back
call insert operation insert(end(),x)push_front
call insert operation insert(begin(),x)erase
Delete a node , Note that the function returns the deleted node pos Iterator for the next node ofpop_front
- pop_back
clear
remove
remove(const T &x) Remove all elements with values of xunique
Remove consecutive but identical elements , eg: unique Before and after
1,2,2,2,1,3,3,4,1
1,2,1,3,4,1transfer ( Internal operation )
It belongs to internal operation - transfer ,transfer(positon,first,last) take [first,last) All the elements in the postion Before , Make a series of nodes next and prev Replacement operation of (3 link 6 Line operation ). For subsequent merge,sort And so on .
Be careful :position The linked list can be linked to [first,last) The linked list belongs to the same , It can also belong to different .
When they belong to the same ,position Can't be in [first,last) Within the interval .splice
splice(iterator pos,list &x);
splice(iterator pos, list &, iterator first, iterator last);
External interface , Internal calls transfer operation .sort
list You can only use your own functions sort Sort , From small to large , Out of commission stl Algorithm sort Function to sort .
When list When the element is a non basic data type such as a class or structure , Need to be right >,< Wait for heavy load . The details are analyzed in the sorting section .
reverse
Reverse the linked list , This operation can be used to change from ascending to descending .merge
Linked list merging ,merge(x) Link list x Merge into this On .
边栏推荐
- Nacos1.1.4 local source code startup
- TypeScript学习【6】 接口类型
- 渗透测试路径字典、爆破字典
- Cloud computing technology
- Clcnet: Rethink integrated modeling with classified confidence network (with source code download)
- The website is frequently suspended, leading to a decline in ranking
- 内网渗透 - 哈希传递攻击
- ^25进程与线程
- Faster RCNN
- 模式识别大作业——PCA&Fisher&KNN&Kmeans
猜你喜欢

Marathon环境下fastdfs和vsftpd和miniIo文件服务器搭建的方式

Recommend this UI automation testing framework and write use cases as colloquially as possible
![[Django学习笔记 - 12]:数据库操作](/img/d8/2c4b6c036532c213477754b6f9758e.png)
[Django学习笔记 - 12]:数据库操作

R language multivariable generalized orthogonal GARCH (go-garch) model for fitting and forecasting high-dimensional volatility time series of stock market

内网渗透 - 哈希传递攻击

MQ消息丢失,消息一致性,重复消费解决方案

ASP. Net core build scheduling service - use generic host with quartz Net

Windows uses php to start ThinkPHP project and deploy configuration

application. Properties mysql. cj. jdbc. Driver red

1- enter the database
随机推荐
Typescript learning [5] type
Test question bank and online simulation test for operation certificate of main principals of hazardous chemical business units in 2022
渗透测试路径字典、爆破字典
Smart curly bracket escape
Debugging -- debugging objects and events
2022年茶艺师(中级)考试题模拟考试题库及模拟考试
优视慕V8投影仪,打开高清新“视”界
TypeScript 学习【8】枚举类型
Listing of Yubang new material on Shenzhen Stock Exchange: market value of 4.7 billion, net profit deducted in the first quarter decreased by 18%
What did we do from March to April?
Codeigniter3 learning notes 5 (form verification)
zsh
Detailed explanation of MySQL field types
2022焊工(初级)特种作业证考试题库及模拟考试
拉下新项目代码爆红
3-4月份我们干了些什么?
2022-06-清华管理学-清华大学-宁向东
Windows10 installs both MySQL 5 and MySQL 8
AQS 之 CyclicBarrier 源码分析
MySQL scheduled backup restore