{"format":"brushup-mindmap-v1","id":"ds-02-linear-list","title":"线性表【王道】","structure":"logic-right","theme":"auto","root":{"id":"2eba13ea4b2aeb783859395f0b","topic":"第二章 线性表","expanded":true,"children":[{"id":"dda968eaa998a8f6078b086684","topic":"线性表的定义和特点","expanded":true,"children":[{"id":"c3c89b7c-a190-48e8-ac6b-d10e35cf199a","topic":"线性表是具有相同特性的数据元素的一个有序序列","expanded":true},{"id":"62b3ccf8-c26d-46ab-8618-e020f74c1f2c","topic":"特征","expanded":true,"children":[{"id":"02ab47ba-ab7e-49b9-9485-1771ea0f37b7","topic":"元素个数有限、具有先后次序、元素类型相同","expanded":true},{"id":"08af05d2-cb74-4927-9eec-3c8963d16034","topic":"开始结点仅有一个直接后继，终端结点仅有一个直接前驱，内部结点仅有一个直接前驱和一个直接后继","expanded":true}]},{"id":"dcf103e1-800e-4d22-be8c-f08e4b641459","topic":"补充","expanded":true,"children":[{"id":"afddf9ba-1423-49cf-9930-4945172d0e48","topic":"线性表是一种逻辑结构，表示元素一对一的相邻关系，顺序表和链表是存储结构","expanded":true}]}]},{"id":"188a311f5cfb7f2a050cb8afc6","topic":"顺序表示（顺序存储结构/顺序映像）","expanded":true,"children":[{"id":"b2b011f3-53de-44ec-9f6e-a5613cb62985","topic":"顺序存储定义：把逻辑上相邻的数据元素存储在物理上相邻的存储单元中的存储结构","expanded":true,"children":[{"id":"f8cdd51c-a77e-4a6d-9ea7-fd11222a5459","topic":"简言之：逻辑上相邻，物理上也相邻","expanded":true}]},{"id":"003c3515-3af5-493e-b331-9a4fcdddf2e3","topic":"特点","expanded":true,"children":[{"id":"05865995-5a63-4ad0-aa27-1c8679389265","topic":"以物理位置相邻表示逻辑关系，占用一片连续的存储空间","expanded":true},{"id":"2a29c565-6085-4a83-80ea-e7e1bc85b151","topic":"优点","expanded":true,"children":[{"id":"f8b169a9-58be-46e1-94c4-8646d9a76dd0","topic":"随机访问，即通过首地址和元素序号可在时间O(1)内找到指定元素","expanded":true}]},{"id":"0df8fa85-1981-4d44-9693-a67982448a78","topic":"缺点","expanded":true,"children":[{"id":"2b1b7003-6b6a-4f83-8448-b0d274d132c5","topic":"插入、删除元素需要移动大量元素、浪费存储空间、数据元素个数不能自由扩充","expanded":true}]}]},{"id":"4a3aa5ba-e757-4118-be71-0f7d67a3e37b","topic":"定义实现","expanded":true,"style":{"borderColor":"#FF9F00","branchColor":"#007C74"},"children":[{"id":"5ed6ee2c-3404-4d37-b391-3b5324b0f5e7","topic":"静态分配","expanded":true,"children":[{"id":"652dbd28-f8b9-46d9-aa17-57eeb920575f","topic":"类型定义","expanded":true,"code":{"lang":"c","code":"typedef struct {\n    ElemType data[MaxSize];\n    int length;\n} SqList; //顺序表类型","title":"SqList","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ElemType ","darkColor":"#DEDBD2"},{"text":"data","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"MaxSize","darkColor":"#DEDBD2"},{"text":"];","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" length","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":" SqList","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //顺序表类型","darkColor":"#908B7E"}]]}}]},{"id":"94b6a40d-0010-44ba-a52c-49542e6c29a9","topic":"动态分配","expanded":true,"children":[{"id":"fc3620a8-da01-447e-aeca-6db1a2f2d4e2","topic":"类型定义","expanded":true,"children":[{"id":"b0c9ed8d-ca3d-4cc6-9c35-f8c277adca7c","topic":"//定义变量\nSqList L; \n//实现\nL.data=(ElemType*)malloc(sizeof(ElemType)*MaxSize);       //C语言\nL.data=new ElemType[MaxSize];                                            //C++","expanded":true,"children":[{"id":"2d6e9248-37a5-4144-ba5e-5d2f9fb41bd6","topic":"C语言","expanded":true,"children":[{"id":"09914ad6-c30f-47f6-8dcf-ff16b1dc3f9a","topic":"malloc(m)函数：开辟m字节长度的地址空间，并返回这段空间的首地址","expanded":true},{"id":"1624fd5e-3356-450f-9135-813b40110490","topic":"sizeof(x)运算：计算变量x的长度","expanded":true},{"id":"c07c2671-3ba6-42b7-89e3-64996be75982","topic":"free(p)函数：释放指针p所指变量的存储空间","expanded":true}]},{"id":"716bad7c-c812-4b58-b43a-19e860c783ed","topic":"C++","expanded":true,"children":[{"id":"fe6f6d19-73b2-4031-a537-771b1afc76f2","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-1f6b4463d25d04.png","width":353.23,"height":156.99}}]}]}],"code":{"lang":"c","code":"typedef struct {\n    ElemType *data;\n    int length;\n} SqList; //顺序表类型","title":"SqList","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ElemType ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"data","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"int","darkColor":"#74CBC4"},{"text":" length","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":" SqList","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":" //顺序表类型","darkColor":"#908B7E"}]]}},{"id":"dbd4bebf-b113-403b-baf4-73378ee027c9","topic":"注意：动态分配不是链式存储，它同样属于顺序存储结构，物理结构没有变化，只是分配的空间大小可以在运行时动态决定","expanded":true}]}]},{"id":"4e7e9ce9-9c18-4b19-8eb3-68eb63393253","topic":"基本操作的实现","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"2ce2e4db-b25e-4d55-be12-2eb9009b8e2b","topic":"注意：线性表元素序号从1开始（逻辑位序和物理位序相差1）","expanded":true,"children":[{"id":"91ab25b5-29f8-4cb9-9b20-78cd4266095a","topic":"合法插入位置：1 <= i <= n+1","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"ceca32c3-2220-4a5a-9d53-4255e91bb295","topic":"插入操作","expanded":true,"children":[{"id":"7217f783-8da0-48ef-9d1a-757fee48ea9c","topic":"在顺序表的指定位置插入新元素，由于表中元素的物理位置是相邻的，所以当插入新元素的时候就需要对表中的元素进行整体移动","expanded":true},{"id":"ffc17a2c-0b15-4d44-aa63-f5e47c77c031","topic":"插入操作的平均移动次数","expanded":true,"children":[{"id":"928c8ce6-3f84-4e2a-84b4-74bac54df4c3","topic":"假设在n+1个位置上插入元素概率为：Pi=1/(n+1)","expanded":true},{"id":"f0dfa39d-647c-46bc-837f-112dddbbbdc9","topic":"","expanded":true,"formula":{"tex":"\\begin{aligned} \\mathrm{E}_{\\mathrm{ins}} &= \\frac{1}{n+1} \\sum_{i=1}^{n+1} (n - i + 1) = \\frac{1}{n+1}(n + \\cdots + 1 + 0) \\\\ &= \\frac{1}{(n+1)}\\frac{n(n+1)}{2} = \\frac{n}{2} \\end{aligned}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mtable rowspacing=\"0.25em\" columnalign=\"right left\" columnspacing=\"0em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><msub><mi mathvariant=\"normal\">E</mi><mrow><mi mathvariant=\"normal\">i</mi><mi mathvariant=\"normal\">n</mi><mi mathvariant=\"normal\">s</mi></mrow></msub></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>=</mo><mfrac><mn>1</mn><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></munderover><mo stretchy=\"false\">(</mo><mi>n</mi><mo>−</mo><mi>i</mi><mo>+</mo><mn>1</mn><mo stretchy=\"false\">)</mo><mo>=</mo><mfrac><mn>1</mn><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></mfrac><mo stretchy=\"false\">(</mo><mi>n</mi><mo>+</mo><mo>⋯</mo><mo>+</mo><mn>1</mn><mo>+</mo><mn>0</mn><mo stretchy=\"false\">)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel=\"0\" displaystyle=\"true\"><mrow><mrow></mrow><mo>=</mo><mfrac><mn>1</mn><mrow><mo stretchy=\"false\">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy=\"false\">)</mo></mrow></mfrac><mfrac><mrow><mi>n</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy=\"false\">)</mo></mrow><mn>2</mn></mfrac><mo>=</mo><mfrac><mi>n</mi><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\\begin{aligned} \\mathrm{E}_{\\mathrm{ins}} &amp;= \\frac{1}{n+1} \\sum_{i=1}^{n+1} (n - i + 1) = \\frac{1}{n+1}(n + \\cdots + 1 + 0) \\\\ &amp;= \\frac{1}{(n+1)}\\frac{n(n+1)}{2} = \\frac{n}{2} \\end{aligned}</annotation></semantics></math></span>"}}]}]},{"id":"b702b968-9e35-45f2-b5da-c328fae8aeef","topic":"删除操作","expanded":true,"children":[{"id":"3b84f39f-1d4d-4377-850b-5d5768486f3d","topic":"删除指定位置元素，将后续元素依次向前移动一个位置","expanded":true},{"id":"3ca73f30-8f8e-498a-8285-f4959c17ab50","topic":"删除操作的平均移动次数","expanded":true,"children":[{"id":"12b66bac-035d-4463-9ffe-6b5ad6cc958c","topic":"假设删除第i个元素概率：Pi=1/n","expanded":true},{"id":"21a01c0a-69ba-4a8c-a33c-4c189499f624","topic":"","expanded":true,"formula":{"tex":"\\mathrm{E}_{\\mathrm{del}} = \\frac{1}{n} \\sum_{i=1}^{n} (n - i) = \\frac{1}{n}\\frac{(n-1)n}{2} = \\frac{n-1}{2}","displayMode":true,"mathml":"<span class=\"katex\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><msub><mi mathvariant=\"normal\">E</mi><mrow><mi mathvariant=\"normal\">d</mi><mi mathvariant=\"normal\">e</mi><mi mathvariant=\"normal\">l</mi></mrow></msub><mo>=</mo><mfrac><mn>1</mn><mi>n</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mo stretchy=\"false\">(</mo><mi>n</mi><mo>−</mo><mi>i</mi><mo stretchy=\"false\">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>n</mi></mfrac><mfrac><mrow><mo stretchy=\"false\">(</mo><mi>n</mi><mo>−</mo><mn>1</mn><mo stretchy=\"false\">)</mo><mi>n</mi></mrow><mn>2</mn></mfrac><mo>=</mo><mfrac><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow><mn>2</mn></mfrac></mrow><annotation encoding=\"application/x-tex\">\\mathrm{E}_{\\mathrm{del}} = \\frac{1}{n} \\sum_{i=1}^{n} (n - i) = \\frac{1}{n}\\frac{(n-1)n}{2} = \\frac{n-1}{2}</annotation></semantics></math></span>"}}]}]},{"id":"9fe93a6e-bd58-467e-89b3-9bca9a1ca35a","topic":"按值查找（顺序查找）","expanded":true,"children":[{"id":"0e217277-6c1b-44fb-9700-9cfe15877478","topic":"在顺序表中查找特定值元素的位置","expanded":true},{"id":"03c19779-9534-4250-a2d2-6c973380efcd","topic":"顺序查找的平均查找长度","expanded":true,"children":[{"id":"fea13843-1dc2-4739-9257-e85e64df0f10","topic":"假设每个记录的查找概率相等：Pi = 1/n","expanded":true},{"id":"6894cd7a-ddbe-4ba3-b8ff-b22a97f50a56","topic":"ASL = P1 + 2P2 + ... + (n-1)Pn-1 + nPn = 1/n×(1+2+...+n)=1/n × n(n+1)/2 = (n+1)/2","expanded":true}]}]}]}]},{"id":"2ecb7bff-3554-4a4a-be33-735b9b5232e8","topic":"链式表示","expanded":true,"children":[{"id":"4c4f94dd-62df-4810-9537-8171641329bd","topic":"用一组物理位置任意的存储单元来存放线性表的数据元素（逻辑次序和物理次序不一定相同）","expanded":true},{"id":"7f242201-e8e0-43d2-a85a-828b845f1659","topic":"结构","expanded":true,"style":{"branchColor":"#7B1FA2"},"children":[{"id":"21c9b1b5-6180-4f84-a815-72a6cede95dc","topic":"结点","expanded":true,"children":[{"id":"b68e93fd-5796-45f2-999e-1eccae87c269","topic":"数据元素的存储映像，由数据域和指针域组成","expanded":true,"children":[{"id":"24c8cfcd-ff54-4677-ac7b-1d54016fc3bf","topic":"数据域data：存储元素数值数据","expanded":true},{"id":"8f681e09-a03e-4894-b4a2-42c969530595","topic":"指针域next：存储直接后继结点的存储位置","expanded":true}]}]},{"id":"e1d41018-5f4d-497d-898f-bd7df6f4d993","topic":"头指针","expanded":true,"children":[{"id":"e74aedca-dce7-4d81-bb20-152152eef44c","topic":"用来标识单链表，始终指向单链表第一个结点","expanded":true}]},{"id":"792dad1a-3110-4fed-b48b-293493a3e7ce","topic":"头结点","expanded":true,"children":[{"id":"a3751f51-0ad0-43f1-aec6-b58e00c2637d","topic":"单链表第一个结点前附加一个结点，头结点数据域可以不设任何信息，也可以记录表长等","expanded":true,"children":[{"id":"9059092d-02fa-4563-9564-5dcd6803e950","topic":"引入头结点后，第一个数据结点和其他数据结点的操作一致，无需特殊处理；且空表和非空表的处理得到统一","expanded":true}]}]}]},{"id":"5be952ee-108e-496c-a6c1-1088541de5b7","topic":"特点","expanded":true,"children":[{"id":"81ee8c9d-c0a5-4d2a-a5c0-42528e5bd4f7","topic":"优点","expanded":true,"children":[{"id":"7d752dbd-c956-4d77-90d1-37b3162ceee2","topic":"解决顺序表大量连续存储单元的缺点，插入和删除操作无需移动元素","expanded":true}]},{"id":"0290539d-4083-452f-8651-eb439e62c653","topic":"缺点","expanded":true,"children":[{"id":"af14c086-f3c4-4477-b0fd-d1ec029bff5d","topic":"指针域浪费空间、查找操作需要从头遍历（顺序查找方式）","expanded":true}]}]},{"id":"7e8a01d6-2dba-4498-b742-a524f710d70d","topic":"单链表","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#7B1FA2"},"children":[{"id":"ec8bf578-2acc-42ea-8c15-b5afacf0a3b3","topic":"定义实现","expanded":true,"children":[{"id":"a7ad431e-dbf3-4eab-9e09-051450052480","topic":"结点类型和链表指针定义","expanded":true,"children":[{"id":"91b87027-0eb8-4bdd-bd5c-93a85b27e7b3","topic":"定义链表L：LinkList L;\n定义结点指针p：LNode *P;","expanded":true}],"code":{"lang":"c","code":"typedef struct Lnode{\n    ElemType data;\n    struct Lnode *next;\n}Lnode, *LinkList;","title":"Lnode / LinkList","tokens":[[{"text":"typedef","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" Lnode","darkColor":"#DEDBD2"},{"text":"{","darkColor":"#BAB5A8"}],[{"text":"    ElemType data","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"    ","darkColor":"#DEDBD2"},{"text":"struct","darkColor":"#8EA4E2"},{"text":" Lnode ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"next","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"}","darkColor":"#BAB5A8"},{"text":"Lnode","darkColor":"#DEDBD2"},{"text":",","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"*","darkColor":"#BAB5A8"},{"text":"LinkList","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]},{"id":"cc253e5a-d84d-4f33-beac-6edfe6d599ab","topic":"操作","expanded":true,"children":[{"id":"824d5308-528f-4f64-824a-0885411938d7","topic":"头插法建立单链表","expanded":true,"children":[{"id":"245f6ca1-fc4e-4fdf-be77-dfa543368c50","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-038b812d14025d.png","width":288.69,"height":120.32},"children":[{"id":"ef56cb95-2c5b-4429-b7fa-410139e2c632","topic":"从一个空表开始，生成新结点，插入到当前链表的表头，即头结点之后","expanded":true},{"id":"f7caf45b-3e4f-4f58-ab6e-910936ba183e","topic":"注意：生成的链表中结点的次序和输入数据顺序相反，可以利用该特点进行链表转置","expanded":true}]}]},{"id":"e8555583-02c3-4826-a624-75a70234118b","topic":"尾插法建立单链表","expanded":true,"children":[{"id":"22e328e0-163e-47d5-a194-fa210467b478","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-fcaeaaa1ba0134.png","width":286.71,"height":88.37},"children":[{"id":"bccd8a2d-cd47-4d0b-81e2-3e0e64a1548d","topic":"将新结点插入到链表的表尾，为此需增加一个尾指针","expanded":true},{"id":"f7e6c8ce-b64f-4d77-ab87-8849fbeb3998","topic":"产生链表结点次序和输入数据顺序一致","expanded":true}]}]},{"id":"8c48089f-4567-4cd2-af29-bab3b7a44d94","topic":"对结点S进行前插操作","expanded":true,"children":[{"id":"44dc6a54-e5b3-4e46-8f74-e601c01e228b","topic":"新建结点X连在结点S后","expanded":true,"children":[{"id":"4bb45256-38dc-442a-b12d-050573c42d2f","topic":"交换X与S中数据","expanded":true}]}]},{"id":"bf80f68f-4b6a-46ac-8fd8-6f3c15430883","topic":"其他操作略（查找、插入、删除、求表长）\n本质上只要学会结点链表定义，其他操作都是对指针的操作，弄清楚箭头顺序即可，原则是确保不会造成断链和结点丢失","expanded":true}]}]},{"id":"339e51bb-d525-4de2-93cc-424e7cbf34b5","topic":"双链表","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"6291d74b-6c86-4e01-9e92-3742b495f337","topic":"概念","expanded":true,"children":[{"id":"b69fed7e-8d13-4613-8841-83a999cead4b","topic":"为了能快速对前驱结点操作，引入双链表。双链表结点中有两个指针priot与next，分别指向其前驱结点和后继结点","expanded":true,"children":[{"id":"c5d784be-8d37-49a5-9751-c8ff3ebbff85","topic":"typedef struct DNode{\n        ElemType data;\n        struct DNode *prior, *next;\n}DNode, *DLinklist","expanded":true}]}]},{"id":"1f805ee0-9309-4a06-88c6-55e5abb8f3e9","topic":"插入操作","expanded":true,"children":[{"id":"f59e1603-7731-45f1-bae5-dd4691d4e1db","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-f22125a611b567.png","width":292.02,"height":128.9},"children":[{"id":"9f837f0e-c98a-4128-978e-9a96a77c211c","topic":"s->next=p->next;         //将结点*s插入到结点*p之后\np->next->prior=s;\ns->prior=p;\np->next=s;","expanded":true,"children":[{"id":"81162f27-2542-4775-bff9-41aa10220f2b","topic":"链表的操作原则是，确保不会造成断链和结点丢失","expanded":true}]}]}]},{"id":"35f5b0b1-deea-494f-93ba-1adb7a7af89e","topic":"删除操作","expanded":true,"children":[{"id":"10dc0b22-2f31-4986-9e83-35422df24bd8","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-7dbf1bf63149d9.png","width":289.24,"height":102.08},"children":[{"id":"60ab1a2a-ea09-4431-b535-0194c4f2a2a3","topic":"p->next=q->next;\nq->next->prior=p;\nfree(q);","expanded":true}]}]}]},{"id":"4a6ce711-62e9-4173-8785-8522427df697","topic":"循环链表","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#7B1FA2"},"children":[{"id":"fd99c6c2-a29f-4ba5-a4d5-63b1fbd6b8d8","topic":"循环单链表","expanded":true,"children":[{"id":"deceadd4-61e1-41a6-bdf5-3ede1689b4b4","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-e373fd68f9eb35.png","width":384.4,"height":58.87},"children":[{"id":"b7bd815c-a32a-4bfe-bdfe-489a26c5de9b","topic":"概念","expanded":true,"children":[{"id":"283e35a9-01a6-41b4-8251-b25f85e3606d","topic":"与单链表区别：表中最后一个结点的指针不是NULL，而指向头结点，形成一个环","expanded":true}]},{"id":"814ff80f-5a4a-405d-a040-a0e22ed8e42f","topic":"判空条件","expanded":true,"children":[{"id":"b9659a0a-f94a-4b1f-adae-30528f814c64","topic":"头结点的指针是否等于头指针","expanded":true}]},{"id":"884937a0-6d8b-4f36-a57b-fc6afa4f7364","topic":"注意：循环单链表一般不设头指针，只设尾指针R（王道讲课似乎都是头指针）","expanded":true}]}]},{"id":"6eb58978-2fb5-4bd2-9ea5-10e08e6833c6","topic":"循环双链表","expanded":true,"children":[{"id":"f36b389d-e2f8-461e-ab8d-454b6beb2d7f","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-cb559d5e3d5148.png","width":315.58,"height":78.9},"children":[{"id":"3624ea3f-6cd5-40ef-93d4-2a6b4cd75c80","topic":"概念","expanded":true,"children":[{"id":"738ff1b6-4fd1-42aa-956a-9aa6fbd9514a","topic":"与循环单链表区别：头结点的prior指针还要指向表尾结点","expanded":true}]},{"id":"d24ef1b2-6afc-4277-8b5c-df54a4ee2585","topic":"判空条件","expanded":true,"children":[{"id":"d2b36598-2ad0-4389-a3c0-78fd6ceb5251","topic":"当循环双链表为空时，头结点的prior域和next域都等于L","expanded":true}]}]}]}]},{"id":"baf34c1d-e3a7-4d27-9f23-234d47f3c36e","topic":"静态链表","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"1e3510b1-d8a2-45a1-b2fa-cbed91c41673","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-80f08267cd9572.png","width":238.01,"height":294.57},"children":[{"id":"53cfdd3e-32ff-4a6b-b473-02ef4b9325d2","topic":"概念","expanded":true,"children":[{"id":"b1f35f94-1ecd-4362-8f70-a0f7a65063a4","topic":"静态链表借助数组来描述线性表的链式存储结构，结点也有数据域和指针域，其指针是结点的相对地址（数组下标，又称游标）","expanded":true}]},{"id":"c554ca59-0541-48d6-a65a-aab402aa47d3","topic":"特点","expanded":true,"children":[{"id":"9906e47d-7b2d-4e25-b5a4-0d0018b0be57","topic":"需要预先分配一块连续内存空间（容量固定不变）、插入删除无需移动元素、不能随机存取","expanded":true}]},{"id":"328a4d42-4b11-457a-9b7a-2969a2c7bcb2","topic":"适用场景","expanded":true,"children":[{"id":"afd9644a-f655-4ed6-8719-3bc61f98b086","topic":"不支持指针的低级语言、数据元素数量固定不变的场景（如操作系统的文件分配表FAT）","expanded":true}]}]}]},{"id":"b852fafc-5faf-4c8a-a33b-37320ca1962c","topic":"不同链表的时间效率比较","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#7B1FA2"},"children":[{"id":"906404cf-6869-4fda-9b7e-cfbedbce36b8","topic":"对比维度","expanded":true,"children":[{"id":"5f7e759c-c648-47b4-84c2-3d4157ead19b","topic":"查找表头结点","expanded":true,"children":[{"id":"98ceb9bb-412f-4c41-a634-0db2e92777fc","topic":"查找表尾结点","expanded":true,"children":[{"id":"e555c4df-26f4-4e3f-bc99-0bb3fb51e038","topic":"查找结点*P的前驱结点","expanded":true}]}]}]},{"id":"ce0aea43-0232-4f2d-a94e-e8081cbbb4b9","topic":"带头结点的单链表L","expanded":true,"children":[{"id":"d224598f-fc88-4d3f-b637-45c805373232","topic":"L->next，时间复杂度O(1)","expanded":true,"children":[{"id":"edd47da6-d90d-49bf-a37f-c34da76a3d16","topic":"从L->next依次向后遍历，时间复杂度O(n)","expanded":true,"children":[{"id":"0e9f52d0-296c-4ab7-8e19-a90cb0a4656a","topic":"通过p->next无法找到其前驱（双指针可以）","expanded":true}]}]}]},{"id":"ff9f3f52-73f6-48cc-a597-54dbd27c3023","topic":"带头结点仅设头指针L的循环单链表","expanded":true,"children":[{"id":"281ebeae-e390-42f0-a5f0-e8adad327df8","topic":"L->next，时间复杂度O(1)","expanded":true,"children":[{"id":"38f103d4-ab10-4b07-ab1a-0673b60eb74f","topic":"从L->next依次向后遍历，时间复杂度O(n)","expanded":true,"children":[{"id":"bdf96a8d-9fdc-41e2-aec6-727f7c35304e","topic":"通过p->next可以找到其前驱，时间复杂度O(n)","expanded":true}]}]}]},{"id":"1e1b9290-3061-401a-9aba-d163bc746f36","topic":"带头结点仅设尾指针R的循环单链表","expanded":true,"children":[{"id":"4534f7ee-fa4b-4ea1-b494-274623cb1d9a","topic":"R->next，时间复杂度O(1)","expanded":true,"children":[{"id":"870ff28d-d7cb-4bf5-9b7a-c741a55c0fb2","topic":"R，时间复杂度O(1)","expanded":true,"children":[{"id":"070aa356-32c5-4add-9fa5-20f5c637e35e","topic":"通过p->next可以找到其前驱，时间复杂度O(n)","expanded":true}]}]}]},{"id":"41bb2235-b3fe-4c9d-b7f5-67cfa38d6563","topic":"带头结点的双向循环链表L","expanded":true,"children":[{"id":"11884277-0227-41c6-84b9-d15a43806ba0","topic":"L->next，时间复杂度O(1)","expanded":true,"children":[{"id":"3b6c4aed-750c-45be-8c73-526d2bd3433e","topic":"L->prior，时间复杂度O(1)","expanded":true,"children":[{"id":"ac18f5fd-4bf5-477b-a278-577af701d700","topic":"p->prior，时间复杂度O(1)","expanded":true}]}]}]}]}]},{"id":"4dc6112d-feb3-4838-96be-efaca58cbf16","topic":"顺序表和链表的比较","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"189ff53e-df09-430f-8dc2-5d4472302f0d","topic":"比较项目\\存储结构","expanded":true,"children":[{"id":"48d1182f-d631-4f2f-8e72-a2659c95e312","topic":"顺序表","expanded":true,"children":[{"id":"e1907bcc-fd35-49e1-aa0d-d6282fecb8bf","topic":"链表","expanded":true}]}]},{"id":"b3339db5-41cd-455b-9007-a658a8b0c9da","topic":"（空间）存储空间","expanded":true,"children":[{"id":"6260953c-eaee-4bf5-bafe-5e2ca58e822c","topic":"预先分配，会导致空间闲置或溢出","expanded":true,"children":[{"id":"84e8d27c-0dd6-4f78-b458-d2556503504b","topic":"动态分配，不会出现闲置或溢出现象","expanded":true}]}]},{"id":"0af1d180-788b-408a-8f72-a89fb85362aa","topic":"（空间）存储密度","expanded":true,"children":[{"id":"50f966b8-1787-4d11-a8c2-c9e79aeb892a","topic":"不用为表示结点间的逻辑关系而增加额外存储开销","expanded":true,"children":[{"id":"c0780367-fcdb-4693-8736-c5765be3cafe","topic":"需要借助指针体现元素间逻辑关系，存储密度小于1","expanded":true}]}]},{"id":"69e6cc7e-11e0-4df4-9f38-de6e0938b0fa","topic":"（时间）存取元素","expanded":true,"children":[{"id":"592ccb58-dc26-40ef-b6a2-9bbf4e987a7f","topic":"随机存取，按位置访问元素时间为O(1)","expanded":true,"children":[{"id":"95d9f944-1819-4e6e-8b06-debb3bb77fbb","topic":"顺序存取，按位置访问元素复杂度为O(n)","expanded":true}]}]},{"id":"7ffba5da-5032-4b37-ba42-be5cf3cdf721","topic":"（时间）插入、删除","expanded":true,"children":[{"id":"8aeb84f0-c795-483e-ab3f-33dbaa0a0497","topic":"平均移动约表中一半元素，时间复杂度O(n)","expanded":true,"children":[{"id":"b87e2e3b-d674-4d17-b068-457f972436fc","topic":"无需移动元素，确定位置后时间复杂度为O(1)","expanded":true}]}]},{"id":"4b8c6f33-4f19-46b7-82fb-3f0855ce257c","topic":"适用情况","expanded":true,"children":[{"id":"7b33ad16-0095-4b49-8a46-348821edc489","topic":"表长变化不大，且能事先确定变化范围\n很少进行插入删除操作，经常按元素位置访问","expanded":true,"children":[{"id":"964dd478-f53d-4d00-a27e-c50cf553433d","topic":"长度变化较大\n频繁进行插入或删除操作","expanded":true}]}]}]},{"id":"b865424d-082c-4eab-9537-2abc15bb35f5","topic":"补充代码","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"91e018b1-6de1-4c6d-bc15-df282465ac75","topic":"C++也可以用STL中的vector容器实现动态增长的数组","expanded":true,"children":[{"id":"b4ed25b0-fef5-4a30-ab44-a87370b28b8e","topic":"STL是C++的标准模版库，也就是C++标准里帮我们写好了一些经常用到的东西，对于基础的数据结构，都已经给我们写好，比如写广度优先，队列的代码就可以直接用STL的queue容器，我们只要调用函数即可\n随便给大家找个使用指南https://blog.csdn.net/weixin_43772166/article/details/104076670\n相当于在处理算法题时候STL可以很方便帮我们完成数据结构部分，不用自己造轮子，但对于考研，如果题目就是让你实现一个循环队列，那就老老实实自己写，总之可以用但最好自己写（自己写相当于在说我很牛，你咋么敢扣分的啊），如果时间不够可以考虑用","expanded":true}]},{"id":"7bbece67-5beb-47a4-9571-1c68989e7e8f","topic":"单链表（数组模拟）","expanded":true,"style":{"branchColor":"#007C74"},"children":[{"id":"19bb0c22-d2ca-4708-9a2a-7ed5a2ee4374","topic":"int v[N], l[N], idx;                        //初始化，分别为值、下一结点坐标、下一结点下标\n\nvoid init(){\n    l[0] = -1;\n    idx = 1;\n}\nvoid insert(int k, int x){             //去head，直接idx=0存头指针，使k无需-1，且消除头结点的特殊操作\n    v[idx] = x;\n    l[idx] = l[k];\n    l[k] = idx++;\n}\nvoid delete_v(int k){\n    l[k] = l[l[k]];\n}","expanded":true}]},{"id":"be811f66-11ce-4adc-b294-fbc4e3d69251","topic":"双向链表（数组模拟）","expanded":true,"children":[{"id":"1ef54632-619e-456e-8f5d-e61b82a2e26b","topic":"int v[N], l[N], r[N], idx;                             //同理\n\nvoid init(){\n    l[0]=-1, r[0]=1, l[1]=0, r[1]=-1;              //用最开始两个结点做头尾指针\n    idx=2;\n}\nvoid insertL(int k,int x){                        //注意这里的三个函数，由于占用了数组前两个元素，题目给的k值需要+1\n    v[idx] = x;\n    l[idx] = l[k];\n    r[idx] = k;\n    r[l[k]] = idx;\n    l[k] = idx++;\n}\nvoid insertR(int k,int x){\n    v[idx] = x;\n    r[idx] = r[k];\n    l[idx] = k;\n    l[r[k]] = idx;\n    r[k] = idx++;\n    \n}\nvoid delete_v(int k){\n    r[l[k]] = r[k];\n    l[r[k]] = l[k];\n}","expanded":true}]}]}]},"relations":[{"id":"b656660f-1da7-4b5a-98b1-379e65dc342e","from":"81162f27-2542-4775-bff9-41aa10220f2b","to":"60ab1a2a-ea09-4431-b535-0194c4f2a2a3","bidirectional":false}]}