mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-03 19:03:42 +08:00
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点 Update the footnotes in the figures * Update mindmap * Reduce the size of the mindmap.png
This commit is contained in:
@@ -7,18 +7,18 @@
|
||||
#include "../include/include.hpp"
|
||||
|
||||
|
||||
/* 双向链表结点 */
|
||||
/* 双向链表节点 */
|
||||
struct DoublyListNode {
|
||||
int val; // 结点值
|
||||
DoublyListNode *next; // 后继结点指针
|
||||
DoublyListNode *prev; // 前驱结点指针
|
||||
int val; // 节点值
|
||||
DoublyListNode *next; // 后继节点指针
|
||||
DoublyListNode *prev; // 前驱节点指针
|
||||
DoublyListNode(int val) : val(val), prev(nullptr), next(nullptr) {}
|
||||
};
|
||||
|
||||
/* 基于双向链表实现的双向队列 */
|
||||
class LinkedListDeque {
|
||||
private:
|
||||
DoublyListNode *front, *rear; // 头结点 front ,尾结点 rear
|
||||
DoublyListNode *front, *rear; // 头节点 front ,尾节点 rear
|
||||
int queSize = 0; // 双向队列的长度
|
||||
|
||||
public:
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
/* 析构方法 */
|
||||
~LinkedListDeque() {
|
||||
// 遍历链表删除结点,释放内存
|
||||
// 遍历链表删除节点,释放内存
|
||||
DoublyListNode *pre, *cur = front;
|
||||
while (cur != nullptr) {
|
||||
pre = cur;
|
||||
@@ -57,13 +57,13 @@ public:
|
||||
// 将 node 添加至链表头部
|
||||
front->prev = node;
|
||||
node->next = front;
|
||||
front = node; // 更新头结点
|
||||
front = node; // 更新头节点
|
||||
// 队尾入队操作
|
||||
} else {
|
||||
// 将 node 添加至链表尾部
|
||||
rear->next = node;
|
||||
node->prev = rear;
|
||||
rear = node; // 更新尾结点
|
||||
rear = node; // 更新尾节点
|
||||
}
|
||||
queSize++; // 更新队列长度
|
||||
}
|
||||
@@ -86,26 +86,26 @@ public:
|
||||
int val;
|
||||
// 队首出队操作
|
||||
if (isFront) {
|
||||
val = front->val; // 暂存头结点值
|
||||
// 删除头结点
|
||||
val = front->val; // 暂存头节点值
|
||||
// 删除头节点
|
||||
DoublyListNode *fNext = front->next;
|
||||
if (fNext != nullptr) {
|
||||
fNext->prev = nullptr;
|
||||
front->next = nullptr;
|
||||
delete front;
|
||||
}
|
||||
front = fNext; // 更新头结点
|
||||
front = fNext; // 更新头节点
|
||||
// 队尾出队操作
|
||||
} else {
|
||||
val = rear->val; // 暂存尾结点值
|
||||
// 删除尾结点
|
||||
val = rear->val; // 暂存尾节点值
|
||||
// 删除尾节点
|
||||
DoublyListNode *rPrev = rear->prev;
|
||||
if (rPrev != nullptr) {
|
||||
rPrev->next = nullptr;
|
||||
rear->prev = nullptr;
|
||||
delete rear;
|
||||
}
|
||||
rear = rPrev; // 更新尾结点
|
||||
rear = rPrev; // 更新尾节点
|
||||
}
|
||||
queSize--; // 更新队列长度
|
||||
return val;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
/* 基于链表实现的队列 */
|
||||
class LinkedListQueue {
|
||||
private:
|
||||
ListNode *front, *rear; // 头结点 front ,尾结点 rear
|
||||
ListNode *front, *rear; // 头节点 front ,尾节点 rear
|
||||
int queSize;
|
||||
|
||||
public:
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
}
|
||||
|
||||
~LinkedListQueue() {
|
||||
// 遍历链表删除结点,释放内存
|
||||
// 遍历链表删除节点,释放内存
|
||||
freeMemoryLinkedList(front);
|
||||
}
|
||||
|
||||
@@ -36,14 +36,14 @@ public:
|
||||
|
||||
/* 入队 */
|
||||
void push(int num) {
|
||||
// 尾结点后添加 num
|
||||
// 尾节点后添加 num
|
||||
ListNode* node = new ListNode(num);
|
||||
// 如果队列为空,则令头、尾结点都指向该结点
|
||||
// 如果队列为空,则令头、尾节点都指向该节点
|
||||
if (front == nullptr) {
|
||||
front = node;
|
||||
rear = node;
|
||||
}
|
||||
// 如果队列不为空,则将该结点添加到尾结点后
|
||||
// 如果队列不为空,则将该节点添加到尾节点后
|
||||
else {
|
||||
rear->next = node;
|
||||
rear = node;
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
/* 出队 */
|
||||
void pop() {
|
||||
int num = peek();
|
||||
// 删除头结点
|
||||
// 删除头节点
|
||||
ListNode *tmp = front;
|
||||
front = front->next;
|
||||
// 释放内存
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
/* 基于链表实现的栈 */
|
||||
class LinkedListStack {
|
||||
private:
|
||||
ListNode* stackTop; // 将头结点作为栈顶
|
||||
ListNode* stackTop; // 将头节点作为栈顶
|
||||
int stkSize; // 栈的长度
|
||||
|
||||
public:
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
}
|
||||
|
||||
~LinkedListStack() {
|
||||
// 遍历链表删除结点,释放内存
|
||||
// 遍历链表删除节点,释放内存
|
||||
freeMemoryLinkedList(stackTop);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user