What & How & Why

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
dsa:notes:dahua_ds:3_linearlist [2018/09/24 15:30] – 外部编辑 127.0.0.1dsa:notes:dahua_ds:3_linearlist [2021/11/11 08:07] (当前版本) codinghare
行 2: 行 2:
 大话数据结构 笔记 第三章\\ 大话数据结构 笔记 第三章\\
 <wrap em>我的笔记均包含大量个人理解内容,存在一定偏差。如果您发现错误,请留言提出,谢谢!</wrap> <wrap em>我的笔记均包含大量个人理解内容,存在一定偏差。如果您发现错误,请留言提出,谢谢!</wrap>
-===== =====+----
 ====线性表的定义==== ====线性表的定义====
 线性表(List)是指的<wrap em>零个或者多个数据元素组成的有限序列</wrap>。它的特点体现在<wrap em>有序</wrap>和<wrap em>有限</wrap>上。用数学描述则有: 线性表(List)是指的<wrap em>零个或者多个数据元素组成的有限序列</wrap>。它的特点体现在<wrap em>有序</wrap>和<wrap em>有限</wrap>上。用数学描述则有:
行 52: 行 52:
   - 验证下标是否在有效范围以内。   - 验证下标是否在有效范围以内。
   - 如果在范围内,返回结果。   - 如果在范围内,返回结果。
-<code:cpp linenums:1>+<code cpp linenums:1>
 if (L.length == 0 || i < 1 || i > L.length) { if (L.length == 0 || i < 1 || i > L.length) {
     return -1;     return -1;
行 64: 行 64:
   - 从最后一个元素开始,往前遍历到第 ''i'' 个元素,把这些元素分别往后移动一位。   - 从最后一个元素开始,往前遍历到第 ''i'' 个元素,把这些元素分别往后移动一位。
   - 在 ''i'' 的位置插入新元素。   - 在 ''i'' 的位置插入新元素。
-<code:cpp linenums:1>+<code cpp linenums:1>
 if(L.length == MAXSIZE) //check if list is full if(L.length == MAXSIZE) //check if list is full
     return -1;     return -1;
行 84: 行 84:
   * 从被删除的元素开始遍历到表尾,分别把这区域的元素都往前移动一位。   * 从被删除的元素开始遍历到表尾,分别把这区域的元素都往前移动一位。
   * 表长减去1。   * 表长减去1。
-<code:cpp linenums:1>+<code cpp linenums:1>
 if (i < 1 || i > L.length) //check if element is in range if (i < 1 || i > L.length) //check if element is in range
     return -1;     return -1;
行 122: 行 122:
 ===链表的数据=== ===链表的数据===
 根据上面的描述,我们需要先定义链表的 Data 模型:具有数据部分和指针部分。我们可以用结构体 / 类来定义这个存储结构: 根据上面的描述,我们需要先定义链表的 Data 模型:具有数据部分和指针部分。我们可以用结构体 / 类来定义这个存储结构:
-<code:cpp linenums:1>+<code cpp linenums:1>
 struct Node { struct Node {
     int data;      int data; 
行 138: 行 138:
   * 如果链表为空,建立初始节点(头节点)   * 如果链表为空,建立初始节点(头节点)
   * 如果链表非空,建立新节点,并用前一个节点指向新节点。   * 如果链表非空,建立新节点,并用前一个节点指向新节点。
-<code:cpp linenums:1>+<code cpp linenums:1>
 Linklist p, r; Linklist p, r;
 *L = (LinkList)malloc( sizeof(Node)); //apply memory for LinkList *L = (LinkList)malloc( sizeof(Node)); //apply memory for LinkList
行 157: 行 157:
   - 如果到了链表的尾部, ''p''的数据部分为空,那证明没有找到第 ''i'' 个元素。   - 如果到了链表的尾部, ''p''的数据部分为空,那证明没有找到第 ''i'' 个元素。
   - 否则的话,''i'' 的元素应该存到了 ''p'' 里面,这时我们返回 ''p''的值就可以。   - 否则的话,''i'' 的元素应该存到了 ''p'' 里面,这时我们返回 ''p''的值就可以。
-<code:cpp linenums>+<code cpp linenums>
 LinkList p; LinkList p;
 p = (*L).next(); p = (*L).next();
行 181: 行 181:
   - 再将前驱结点指向新节点。   - 再将前驱结点指向新节点。
 用代码可以表示为: 用代码可以表示为:
-<code:cpp linenums:1>+<code cpp linenums:1>
 new -> next = front -> next; // copy the pointer info from front node to new node, use the info point to the rear node new -> next = front -> next; // copy the pointer info from front node to new node, use the info point to the rear node
 front -> next = new; // then let front point to the new node front -> next = new; // then let front point to the new node
行 204: 行 204:
 \\ \\
 用代码可以表示为: 用代码可以表示为:
-<code:cpp linenums:1>+<code cpp linenums:1>
 front -> next = new -> next; front -> next = new -> next;
 </code> </code>