当前位置: 首页 > news >正文

[STL]list使用介绍

[STL]list使用

注:本文测试环境是visual studio2019。

文章目录

  • [STL]list使用
    • 1. list介绍
    • 2. 构造函数
    • 3. 迭代器相关函数
      • begin函数和end函数
      • rbegin函数和rend函数
    • 4. 容量相关函数
      • empty函数
      • size函数
    • 5. 数据修改函数
      • push_back函数和pop_back函数
      • push_front函数和pop_front函数
      • insert函数和erase函数
      • swap函数
      • resize函数
      • clear函数
    • 6. 数据操作函数
      • sort函数
      • reverse函数
      • merge函数
      • unique函数
      • remove函数
      • splice函数

1. list介绍

  1. list是可以在常量时间内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。
  2. list的底层是双向链表结构,双向链表中每个元素存储在互不相关的独立节点中,在节点中通过指针指向其前一个元素和后一个元素。
  3. list与forward_list非常相似:最主要的不同在于forward_list是单链表,只能朝前迭代,已让其更简单高效。
  4. 与其他的序列式容器相比(array,vector,deque),list通常在任意位置进行插入、移除元素的执行效率更好。
  5. 与其他序列式容器相比,list和forward_list最大的缺陷是不支持任意位置的随机访问,比如:要访问list 的第6个元素,必须从已知的位置(比如头部或者尾部)迭代到该位置。

2. 构造函数

image-20230618212401437

(1)构造函数

默认构造函数。

list<int> l; //创建一个空list

(2)构造函数

创建一个有n个结点,结点数据为val的list。

list<int> l(10, 66); 

(3)构造函数

使用迭代器构造列表。

vector<int> v(10, 6);
list<int> l(v.begin(), v.end()); //创建一个存储int类型的链表,使用v初始化数据

(4)构造函数

拷贝构造函数

list<int> l1(10,6);
list<int> l2(l1); //使用l2拷贝构造l1

3. 迭代器相关函数

begin函数和end函数

begin函数:

返回指向list第一个结点的正向迭代器。

end函数:

返回指向list结尾的正向迭代器。

#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main()
{vector<int> v;v.push_back(1); //在list中尾插数据1v.push_back(2); //在list中尾插数据2v.push_back(3);	//在list中尾插数据3v.push_back(4);	//在list中尾插数据4list<int> l(v.begin(), v.end());list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";it++;}cout << endl; //输出为 1 2 3 4return 0;
}

rbegin函数和rend函数

rbegin函数:

返回指向list最后一个含有数据的结点的反向迭代器。

rend函数:

指向list反向结尾的反向迭代器。

#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main()
{vector<int> v;v.push_back(1); //在list中尾插数据1v.push_back(2); //在list中尾插数据2v.push_back(3);	//在list中尾插数据3v.push_back(4);	//在list中尾插数据4list<int> l(v.begin(), v.end());list<int>::reverse_iterator it = l.rbegin();while (it != l.rend()){cout << *it << " ";it++;}cout << endl; //输出为 4 3 2 1return 0;
}

4. 容量相关函数

empty函数

判断list是否为空.

#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main()
{list<int> l1;list<int> l2(5, 6);cout << l1.empty() << endl;//输出为1cout << l2.empty() << endl;//输出为0return 0;
}

size函数

获取list存储的结点个数。

#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main()
{vector<int> v;v.push_back(1); //在list中尾插数据1v.push_back(2); //在list中尾插数据2v.push_back(3);	//在list中尾插数据3v.push_back(4);	//在list中尾插数据4list<int> l(v.begin(), v.end());cout << l.size() << endl;  //输出为4return 0;
}

5. 数据修改函数

push_back函数和pop_back函数

push_back函数:

在list结尾插入结点。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);cout << l.size() << endl; //输出为3return 0;
}

pop_back函数:

在list结尾删除结点。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);cout << l.size() << endl; //输出为3l.pop_back();l.pop_back();cout << l.size() << endl; //输出为1l.pop_back();//l.pop_back(); -- 报错 -- 没有结点可删return 0;
}

push_front函数和pop_front函数

push_front函数:

在list中头插结点。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_front(1);l.push_front(2);l.push_front(3);l.push_front(4);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl; // 输出为 4 3 2 1return 0;
}

pop_front函数:

在list中头删结点。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_front(1);l.push_front(2);l.push_front(3);l.push_front(4);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl;l.pop_front();l.pop_front();it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl; // 输出为 2 1return 0;
}

insert函数和erase函数

和vector容器类似,list容器也没有提供find函数,而insert函数和erase函数是需要配合迭代器使用的,因此需要使用算法库的find函数。

image-20230619211015257

find函数查找成功会返回指向数据的迭代器,失败会返回传入的last迭代器,注意find函数的查找范围是从first迭代器至last迭代器前,不包括last迭代器。

insert函数

功能1: 在某一位置插入结点。

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);list<int>::iterator pos = find(l.begin(), l.end(), 2);l.insert(pos, 66);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl; //输出为1 66 2 3 4return 0;
}

功能2: 在某一位置插入n个存储相同数据的结点。

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);list<int>::iterator pos = find(l.begin(), l.end(), 2);l.insert(pos, 3, 66);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl; //输出为1 66 66 66 2 3 4return 0;
}

功能3: 传入其他list容器或者其他类型容器的迭代器,将传入的迭代器区间内的数据插入。

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{list<int> l1(3, 66);list<int> l2;l2.push_back(1);l2.push_back(2);l2.push_back(3);list<int>::iterator pos = find(l2.begin(), l2.end(), 2);l2.insert(pos, l1.begin(), l1.end());list<int>::iterator it = l2.begin();while (it != l2.end()){cout << *it << " ";++it;}cout << endl;  //输出为1 66 66 66 2 3return 0;
}

erase函数

功能1: 删除迭代器指向的结点。

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);list<int>::iterator pos = find(l.begin(), l.end(), 2);l.erase(pos);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl; // 输出为 1 3return 0;
}

功能2: 将迭代器范围的结点都删除。

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);l.push_back(5);list<int>::iterator start = find(l.begin(), l.end(), 2);list<int>::iterator finish = find(l.begin(), l.end(), 5);l.erase(start, finish);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << " ";++it;}cout << endl; // 输出为 1 5return 0;
}

swap函数

将两个list数据交换,通过交换list指向的头结点实现。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l1(3, 66);list<int> l2;l2.push_back(1);l2.push_back(2);l2.push_back(3);l1.swap(l2);list<int>::iterator it1 = l1.begin();while (it1 != l1.end()){cout << *it1 << " ";  //输出为 1 2 3++it1;}cout << endl;list<int>::iterator it2 = l2.begin();while (it2 != l2.end()){cout << *it2 << " "; //输出为 66 66 66++it2;}cout << endl;return 0;
}

resize函数

image-20230619215305106

  1. 如果n < size, 会将结点删除至list只有n个结点,由于list结点的释放成本是不高的,因此不同于vector只是将末尾指向修改,list会实际上的在调用resize函数时的删除结点。
  2. 如果n > size,就将插入结点使得list有n个结点
#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);l.push_back(5);cout << l.size() << endl; //输出为5l.resize(3); // n < sizecout << l.size() << endl; //输出为3l.resize(6); // n > sizecout << l.size() << endl; //输出为6return 0;
}

clear函数

释放所有结点,使得list为空链表。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l(66, 6);cout << l.size() << endl; // 输出为66l.clear();cout << l.size() << endl; // 输出为0return 0;
}

6. 数据操作函数

sort函数

对list中的数据进行排序。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> l1;l1.push_back(2);l1.push_back(1);l1.push_back(4);l1.push_back(7);l1.push_back(5);l1.push_back(9);l1.push_back(8);l1.sort();list<int>::iterator it = l1.begin();it = l1.begin();while (it != l1.end()){cout << *it << ' ';  //输出为: 1 2 4 5 7 8 9it++;}return 0;
}

注: 由于list是链表实现的,迭代器是双向迭代器,因此不能调用algorithm库内的sort函数,因此需要单独设计sort函数,但是list的sort函数由于结构原因导致性能不高。

reverse函数

将list内的结点逆置。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << ' ';  //输出为: 1 2 3 4it++;}l.reverse(); //将list逆置it = l.begin();while (it != l.end()){cout << *it << ' '; //输出为: 4 3 2 1it++;}cout << endl;return 0;
}

merge函数

如果两个list有序并且排序方式相同,可以将一个list的结点连接到另一个list上并保持有序,排序方式和连接前相同。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l1;l1.push_back(1);l1.push_back(2);l1.push_back(3);l1.push_back(4);list<int> l2;l2.push_back(6);l2.push_back(7);l2.push_back(8);l2.push_back(9);l2.merge(l1); //将l1的结点连接到l2,连接后l1为空list<int>::iterator it = l2.begin();while (it != l2.end()){cout << *it << ' ';it++;}cout << endl;return 0;
}

unique函数

只能给数据有序的list进行数据去重操作,如果数据无序去重操作会出现问题。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(2);l.push_back(2);l.push_back(3);l.push_back(3);l.push_back(3);l.push_back(4);l.unique();	//对list内的数据去重list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << ' ';	// 输出为: 1 2 3 4it++;}cout << endl;return 0;
}

remove函数

查找对应的数据并进行删除操作,数据存在就删除,不存在不会进行任何操作。

#include <iostream>
#include <list>
using namespace std;
int main()
{list<int> l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);l.remove(3); //删除数据为3的结点list<int>::iterator it = l.begin();while (it != l.end()){cout << *it << ' '; //输出为: 1 2 4it++;}cout << endl;return 0;
}

splice函数

将以一个list的指定部分的结点转移给其他list。

#include <iostream>
#include <list>
using namespace std;int main()
{list<int> l1;l1.push_back(1);l1.push_back(2);l1.push_back(3);l1.push_back(4);list<int> l2;l2.push_back(5);l2.push_back(6);l2.push_back(9);l2.push_back(8);list<int>::iterator it = l1.begin();l1.splice(it, l2); //将l2的所有结点转移到l1的begin位置it = l1.begin();while (it != l1.end()){cout << *it << ' '; //输出为:5 6 9 8 1 2 3 4it++;}return 0;
}

相关文章:

[STL]list使用介绍

[STL]list使用 注&#xff1a;本文测试环境是visual studio2019。 文章目录 [STL]list使用1. list介绍2. 构造函数3. 迭代器相关函数begin函数和end函数rbegin函数和rend函数 4. 容量相关函数empty函数size函数 5. 数据修改函数push_back函数和pop_back函数push_front函数和pop…...

k8s服务发现之第五弹--使用 Service 连接到应用

Kubernetes 的网络模型 通过前面教程的学习&#xff0c;我们已经可以将容器化的应用程序在 Kubernetes 中运行起来&#xff0c;并且发布到 Kubernetes 内/外的网络上。 通常&#xff0c;Docker 使用一种 host-private 的联网方式&#xff0c;在此情况下&#xff0c;只有两个容…...

SAP ABAP 自定义表数据导入

一:效果展示&#xff1a; 读取 Excel 数据到 SAP 数据库表。 二&#xff1a;源码&#xff1a; *&---------------------------------------------------------------------* *& Report ZTEST_DRW02 *&----------------------------------------------------------…...

目标检测识别——大恒(DaHeng)相机操作与控制编程

文章目录 引言正文相关开发库的介绍编程准备配置引用头文件GalaxyIncludes.h配置lib文件 具体编程过程初始化和反初始化枚举设备开关设备 属性控制属性控制器种类 图像采集控制和图像处理采单帧回调采集 总结 引言 在做老师的横向项目时&#xff0c;需要用大恒相机&#xff0c…...

国标GB28181视频监控平台EasyGBS视频无法播放,抓包返回ICMP是什么原因?

国标GB28181视频平台EasyGBS是基于国标GB/T28181协议的行业内安防视频流媒体能力平台&#xff0c;可实现的视频功能包括&#xff1a;实时监控直播、录像、检索与回看、语音对讲、云存储、告警、平台级联等功能。国标GB28181视频监控平台部署简单、可拓展性强&#xff0c;支持将…...

如何正确使用npm常用命令

npm常用命令&#xff1a; 官方文档&#xff1a;CLI Commands | npm Docs 1. npm -v&#xff1a;查看 npm 版本 2. npm init&#xff1a;初始化后会出现一个 Package.json 配置文件&#xff0c;可以在后面加上 -y&#xff0c;快速跳到问答界面 3. npm install&#xff1a;会…...

无人机影像配准并发布(共线方程)

无人机影像 DEM 计算四个角点坐标&#xff08;刚性变换&#xff09; 像空间坐标&#xff08;x,y,-f&#xff09; 像空间坐标畸变纠正 deltax,deltay 已知(x,y)&#xff0c;求解(X,Y, Z)或者(Lat,Lon) 这里的Z是DEM上获取的坐标和Zs为相机坐标的高程&#xff0c;如果均为已…...

openGauss学习笔记-23 openGauss 简单数据管理-时间/日期函数和操作符

文章目录 openGauss学习笔记-23 openGauss 简单数据管理-时间/日期函数和操作符23.1 时间日期操作符23.2 时间/日期函数23.3 TIMESTAMPDIFF23.4 EXTRACT23.5 date_part openGauss学习笔记-23 openGauss 简单数据管理-时间/日期函数和操作符 23.1 时间日期操作符 用户在使用时…...

C++OpenCV(7):图像形态学基础操作

&#x1f506; 文章首发于我的个人博客&#xff1a;欢迎大佬们来逛逛 &#x1f506; OpenCV项目地址及源代码&#xff1a;点击这里 文章目录 膨胀与腐蚀形态学基础 膨胀与腐蚀 膨胀与腐蚀是数学形态学在图像处理中最基础的操作。 膨胀操作是取每个位置领域内最大值&#xff0…...

Appium+python自动化(二十二)- 控件坐标获取(超详解)

简介 有些小伙伴或者是童鞋可能会好奇会问上一篇中的那个monkey脚本里的坐标点是如何获取的&#xff0c;不是自己随便蒙的猜的&#xff0c;或者是自己用目光或者是尺子量出来的吧&#xff0c;答案当然是&#xff1a;NO。获取控件坐标点的方式这里宏哥给小伙伴们分享和讲解三种方…...

Tensorflow benchmark 实操指南

环境搭建篇见环境搭建-CentOS7下Nvidia Docker容器基于TensorFlow1.15测试GPU_东方狱兔的博客-CSDN博客 1. 下载Benchmarks源码 从 TensorFlow 的 Github 仓库上下载 TensorFlow Benchmarks&#xff0c;可以通过以下命令来下载 https://github.com/tensorflow/benchmarks 我…...

【linux】调试工具介绍

文章目录 前言一、kdb二、ftrace三、gdb 前言 在Linux内核调试过程中&#xff0c;可以使用各种工具和技术来诊断和解决问题。以下是一些常用的Linux内核调试方法&#xff1a; printk&#xff1a;printk是Linux内核中的打印函数&#xff0c;可以在代码中插入打印语句来输出调试…...

2.获取DOM元素

获取DOM元素就是利用JS选择页面中的标签元素 2.1 根据CSS选择器来获取DOM元素(重点) 2.1.1选择匹配的第一个元素 语法: document.querySelector( css选择器 )参数: 包含一个或多个有效的CSS选择器 字符串 返回值: CSS选择器匹配的第一个元素&#xff0c;一个HTMLElement对象…...

flask中redirect、url_for、endpoint介绍

flask中redirect、url_for、endpoint介绍 redirect 在 Flask 中&#xff0c;redirect() 是一个非常有用的函数&#xff0c;可以使服务器发送一个HTTP响应&#xff0c;指示客户端&#xff08;通常是浏览器&#xff09;自动导航到新的 URL。基本上&#xff0c;它是用来重定向用…...

《MySQL》第十二篇 数据类型

目录 一. 整数类型二. 浮点类型三. 日期和时间类型四. 字符串类型五. 枚举值类型六. 二进制类型七. 小结 MySQL 支持多种数据类型&#xff0c;学习好数据类型&#xff0c;才能更好的学习 MySQL 表的设计&#xff0c;让表的设计更加合理。 一. 整数类型 类型大小SIGNED(有符号)…...

Python与OpenCV环境中,借助SIFT、单应性、KNN以及Ransac技术进行实现的图像拼接算法详细解析及应用

一、引言 在当今数字化时代,图像处理技术的重要性不言而喻。它在无人驾驶、计算机视觉、人脸识别等领域发挥着关键作用。作为图像处理的一个重要部分,图像拼接算法是实现广阔视野图像的重要手段。今天我们将会讲解在Python和OpenCV环境下,如何使用SIFT、单应性、KNN以及Ran…...

苍穹外卖Day01项目日志

1.软件开发流程和人员分工是怎样的&#xff1f; 软件开发流程 一个软件是怎么被开发出来的&#xff1f; 需求分析 先得知道软件定位人群、用户群体、有什么功能、要实现什么效果等。 需要得到需求规格说明书、产品原型。 需求规格说明书 其中前后端工程师要关注的就是产品原…...

Netty学习(二)

文章目录 二. Netty 入门1. 概述1.1 Netty 是什么&#xff1f;1.2 Netty 的作者1.3 Netty 的地位1.4 Netty 的优势 2. Hello World2.1 目标加入依赖 2.2 服务器端2.3 客户端2.4 流程梳理课堂示例服务端客户端 分析提示&#xff08;重要&#xff09; 3. 组件3.1 EventLoop事件循…...

ReactRouterv5在BrowserRouter和HashRouter模式下对location.state的支持

结论&#xff1a;HashRouter不支持location.state 文档&#xff1a;ReactRouter v5 从文档可看到history.push()方法支持2个参数&#xff1a;path, [state] state即是location.state&#xff0c;常用于隐式地传递状态参数 但文档未提的是&#xff0c;仅适用于BrowserRouter&am…...

Aerotech系列文章(3)运动设置命令Motion Setup Commands

1.运动设置命令Motion Setup Commands 斜坡类型&#xff1a; 直线&#xff0c;S曲线&#xff0c;与正弦曲线 Enumerator: RAMPTYPE_Linear Linear-based ramp type. RAMPTYPE_Scurve S-curve-based ramp type. RAMPTYPE_Sine Sine-based ramp type. 函数原型&a…...

HTML 语义化

目录 HTML 语义化HTML5 新特性HTML 语义化的好处语义化标签的使用场景最佳实践 HTML 语义化 HTML5 新特性 标准答案&#xff1a; 语义化标签&#xff1a; <header>&#xff1a;页头<nav>&#xff1a;导航<main>&#xff1a;主要内容<article>&#x…...

应用升级/灾备测试时使用guarantee 闪回点迅速回退

1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间&#xff0c; 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点&#xff0c;不需要开启数据库闪回。…...

Java 8 Stream API 入门到实践详解

一、告别 for 循环&#xff01; 传统痛点&#xff1a; Java 8 之前&#xff0c;集合操作离不开冗长的 for 循环和匿名类。例如&#xff0c;过滤列表中的偶数&#xff1a; List<Integer> list Arrays.asList(1, 2, 3, 4, 5); List<Integer> evens new ArrayList…...

如何在看板中体现优先级变化

在看板中有效体现优先级变化的关键措施包括&#xff1a;采用颜色或标签标识优先级、设置任务排序规则、使用独立的优先级列或泳道、结合自动化规则同步优先级变化、建立定期的优先级审查流程。其中&#xff0c;设置任务排序规则尤其重要&#xff0c;因为它让看板视觉上直观地体…...

(二)TensorRT-LLM | 模型导出(v0.20.0rc3)

0. 概述 上一节 对安装和使用有个基本介绍。根据这个 issue 的描述&#xff0c;后续 TensorRT-LLM 团队可能更专注于更新和维护 pytorch backend。但 tensorrt backend 作为先前一直开发的工作&#xff0c;其中包含了大量可以学习的地方。本文主要看看它导出模型的部分&#x…...

macOS多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用

文章目录 问题现象问题原因解决办法 问题现象 macOS启动台&#xff08;Launchpad&#xff09;多出来了&#xff1a;Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用。 问题原因 很明显&#xff0c;都是Google家的办公全家桶。这些应用并不是通过独立安装的…...

Python爬虫(一):爬虫伪装

一、网站防爬机制概述 在当今互联网环境中&#xff0c;具有一定规模或盈利性质的网站几乎都实施了各种防爬措施。这些措施主要分为两大类&#xff1a; 身份验证机制&#xff1a;直接将未经授权的爬虫阻挡在外反爬技术体系&#xff1a;通过各种技术手段增加爬虫获取数据的难度…...

爬虫基础学习day2

# 爬虫设计领域 工商&#xff1a;企查查、天眼查短视频&#xff1a;抖音、快手、西瓜 ---> 飞瓜电商&#xff1a;京东、淘宝、聚美优品、亚马逊 ---> 分析店铺经营决策标题、排名航空&#xff1a;抓取所有航空公司价格 ---> 去哪儿自媒体&#xff1a;采集自媒体数据进…...

HDFS分布式存储 zookeeper

hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架&#xff0c;允许使用简单的变成模型跨计算机对大型集群进行分布式处理&#xff08;1.海量的数据存储 2.海量数据的计算&#xff09;Hadoop核心组件 hdfs&#xff08;分布式文件存储系统&#xff09;&a…...

MySQL 索引底层结构揭秘:B-Tree 与 B+Tree 的区别与应用

文章目录 一、背景知识&#xff1a;什么是 B-Tree 和 BTree&#xff1f; B-Tree&#xff08;平衡多路查找树&#xff09; BTree&#xff08;B-Tree 的变种&#xff09; 二、结构对比&#xff1a;一张图看懂 三、为什么 MySQL InnoDB 选择 BTree&#xff1f; 1. 范围查询更快 2…...