当前位置:网站首页>19.03 vessel description and simple application examples continued
19.03 vessel description and simple application examples continued
2022-06-29 03:20:00 【zzyzxb】
One :deque and stack: Sequence containers
<1>deque: deque double-enden queue( Two way opening ). It's like a dynamic array , Both the header and the tail insert and delete data very quickly .
#include <deque>
#include <iostream>
using namespace std;
class A
{
public:
A(int tmpv) :m_i(tmpv) // Constructors
{
cout << "A::A() Constructor execution " << endl;
}
A(const A& tmpA) :m_i(tmpA.m_i)
{
cout << "A::A() Copy constructor execution for " << endl;
}
~A()
{
cout << "A::~A() The destructor of " << endl;
}
public:
int m_i;
};
void func()
{
deque<A>mydeque;
for (int i = 0; i < 5; i++)
{
cout << "----------begin1------------" << endl;
mydeque.push_front(A(i));
cout << "----------end1--------------" << endl;
}
for (int i = 0; i < 5; i++)
{
cout << "----------begin2------------" << endl;
mydeque.push_back(A(i));
cout << "----------end2--------------" << endl;
}
for (int i = 0; i < mydeque.size(); i++)
{
cout << " Subscript to be i = " << i << " The value of is " << mydeque[i].m_i << endl;
// Output address
printf(" The address of each element is : %p\n", &mydeque[i]);
}
}
int main()
{
func();
return 0;
}

summary : Internally, it uses a segmented array to store , Segmented continuous memory .
<2>stack( Stack / Stack ): Last in, first out , There is only one opening , Just put deque The left opening is sealed , We can think of it as a stack.

and vector The difference between :vector Supports inserting and deleting from the middle , Although the efficiency is not high .
stack It only supports putting elements from the top of the stack and taking them out from the top of the stack ( Delete ) Elements . This characteristic is stack The original intention of the container design .
deque It actually contains stack function .
Two :queue
queue: queue . This is a normal queue : fifo , Compare basic data structures ;
deque Also includes this queue function .

3、 ... and :list
Double linked list , There is no need to connect the memory between the elements ; Search efficiency is not outstanding , Inserting and deleting elements anywhere is very fast .
During the interview ,vector and list difference :
<1>vector It's like an array , Its memory space is continuous ;list Double linked list , Memory space is not continuous ( At least memory space is not required to be continuous ).
<2>vector Inserting elements from the middle or the beginning is inefficient , however list Inserting elements is very efficient .
<3>vector When there is not enough memory , Will find a new piece of memory , Destruct the original memory object , Rebuild the object in the newly found memory .
<4>vector Efficient random access , and list You can't do that , For example, to access the fifth element .vector Memory is continuous , You can navigate to the fifth element at a glance .list Find the fifth element , To follow a chain all the way down , Until you find the fifth element , therefore vector Random access is faster , and list Random access is slow .
Four : other
边栏推荐
- PMP Business Analysis Overview
- Démarrer le test - test d'intégration
- 蓝桥杯2022初赛——扫雷
- 设备监理师证书含金量怎样?值得考吗?
- 2022/02/15
- MATALB signal processing - signal transformation (6)
- [North Asia data recovery] data recovery case of ibm-ds3512 storage server RAID5 damaged data loss
- Is it safe for qiniu school to open an account in 2022?
- 如何在关闭socket连接的时候跳过TIME_WAIT的等待状态
- Etcd tutorial - Chapter 6 etcd core API V3
猜你喜欢

Want to be an equipment manager? If you meet these three conditions, you can

Problem - ADB shellerror: insufficient permissions for device: verify udev rules
![Jerry's watch pause [chapter]](/img/57/487ca3dd40e5a7bafdbbe4a7c331e6.jpg)
Jerry's watch pause [chapter]
![二叉树的层序遍历 II[层序遍历方式之一 ->递归遍历 + level]](/img/f9/efb73dd6047e6d5833581376904788.png)
二叉树的层序遍历 II[层序遍历方式之一 ->递归遍历 + level]

2022-2028 global long wave infrared camera and camera core industry research and trend analysis report

逆序对对数计算,顺序对对数计算——归并排序

蓝桥杯2022初赛——扫雷

图扑软件智慧能源一体化管控平台
![Jerry's monitoring alarm clock [chapter]](/img/b7/a5ca7a79af51bd79e4f5c1322b72ff.jpg)
Jerry's monitoring alarm clock [chapter]

Problème - Ajouter shellerror: permissions d'instrumentation pour le périphérique: vérifier les règles udev.
随机推荐
Jerry's watch stops moving [chapter]
PAT甲级 A1057 Stack
Allegro's method of setting network flying line and network color
Tortoise 没有显示绿色图标
不同的二叉搜索树[自下而上回溯生成树+记忆搜索--空间换时间]
FortiGate firewall configuration log uploading regularly
allegro设置网络飞线以及网络颜色的方法
map,set用pari作为key值,如何定义
Is the account opening of GF Securities really safe and reliable
[together with Shangshui Shuo series] day 6-strong liver academic paper! The most detailed explanation!
2022-2028 global industrial lithium chloride industry research and trend analysis report
Quick sort, query the k-largest number of the sequence
1110: nearest common ancestor (function topic)
For safe login of wechat applet, the openid returned by wechat must be verified first to ensure the uniqueness of information.
gcc编译器包
Redu.us took the initiative to transform, and the operation leader of China's charging pile emerged
FPGA (VIII) RTL code IV (basic circuit design 1)
Linear and nonlinear structures
Bluebridge cup 2022 preliminaries - minesweeping
Probe into metacosmic storage, the next explosive point in the data storage market?