mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58: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:
@ -4,11 +4,11 @@
|
||||
* Author: Zhuo Qinyue (1403450829@qq.com)
|
||||
*/
|
||||
|
||||
/* 双向链表结点 */
|
||||
/* 双向链表节点 */
|
||||
class ListNode {
|
||||
prev; // 前驱结点引用 (指针)
|
||||
next; // 后继结点引用 (指针)
|
||||
val; // 结点值
|
||||
prev; // 前驱节点引用 (指针)
|
||||
next; // 后继节点引用 (指针)
|
||||
val; // 节点值
|
||||
|
||||
constructor(val) {
|
||||
this.val = val;
|
||||
@ -19,8 +19,8 @@ class ListNode {
|
||||
|
||||
/* 基于双向链表实现的双向队列 */
|
||||
class LinkedListDeque {
|
||||
#front; // 头结点 front
|
||||
#rear; // 尾结点 rear
|
||||
#front; // 头节点 front
|
||||
#rear; // 尾节点 rear
|
||||
#queSize; // 双向队列的长度
|
||||
|
||||
constructor() {
|
||||
@ -40,7 +40,7 @@ class LinkedListDeque {
|
||||
// 将 node 添加至链表尾部
|
||||
this.#rear.next = node;
|
||||
node.prev = this.#rear;
|
||||
this.#rear = node; // 更新尾结点
|
||||
this.#rear = node; // 更新尾节点
|
||||
}
|
||||
this.#queSize++;
|
||||
}
|
||||
@ -56,7 +56,7 @@ class LinkedListDeque {
|
||||
// 将 node 添加至链表头部
|
||||
this.#front.prev = node;
|
||||
node.next = this.#front;
|
||||
this.#front = node; // 更新头结点
|
||||
this.#front = node; // 更新头节点
|
||||
}
|
||||
this.#queSize++;
|
||||
}
|
||||
@ -66,14 +66,14 @@ class LinkedListDeque {
|
||||
if (this.#queSize === 0) {
|
||||
return null;
|
||||
}
|
||||
const value = this.#rear.val; // 存储尾结点值
|
||||
// 删除尾结点
|
||||
const value = this.#rear.val; // 存储尾节点值
|
||||
// 删除尾节点
|
||||
let temp = this.#rear.prev;
|
||||
if (temp !== null) {
|
||||
temp.next = null;
|
||||
this.#rear.prev = null;
|
||||
}
|
||||
this.#rear = temp; // 更新尾结点
|
||||
this.#rear = temp; // 更新尾节点
|
||||
this.#queSize--;
|
||||
return value;
|
||||
}
|
||||
@ -83,14 +83,14 @@ class LinkedListDeque {
|
||||
if (this.#queSize === 0) {
|
||||
return null;
|
||||
}
|
||||
const value = this.#front.val; // 存储尾结点值
|
||||
// 删除头结点
|
||||
const value = this.#front.val; // 存储尾节点值
|
||||
// 删除头节点
|
||||
let temp = this.#front.next;
|
||||
if (temp !== null) {
|
||||
temp.prev = null;
|
||||
this.#front.next = null;
|
||||
}
|
||||
this.#front = temp; // 更新头结点
|
||||
this.#front = temp; // 更新头节点
|
||||
this.#queSize--;
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ const { ListNode } = require("../modules/ListNode");
|
||||
|
||||
/* 基于链表实现的队列 */
|
||||
class LinkedListQueue {
|
||||
#front; // 头结点 #front
|
||||
#rear; // 尾结点 #rear
|
||||
#front; // 头节点 #front
|
||||
#rear; // 尾节点 #rear
|
||||
#queSize = 0;
|
||||
|
||||
constructor() {
|
||||
@ -29,13 +29,13 @@ class LinkedListQueue {
|
||||
|
||||
/* 入队 */
|
||||
push(num) {
|
||||
// 尾结点后添加 num
|
||||
// 尾节点后添加 num
|
||||
const node = new ListNode(num);
|
||||
// 如果队列为空,则令头、尾结点都指向该结点
|
||||
// 如果队列为空,则令头、尾节点都指向该节点
|
||||
if (!this.#front) {
|
||||
this.#front = node;
|
||||
this.#rear = node;
|
||||
// 如果队列不为空,则将该结点添加到尾结点后
|
||||
// 如果队列不为空,则将该节点添加到尾节点后
|
||||
} else {
|
||||
this.#rear.next = node;
|
||||
this.#rear = node;
|
||||
@ -46,7 +46,7 @@ class LinkedListQueue {
|
||||
/* 出队 */
|
||||
pop() {
|
||||
const num = this.peek();
|
||||
// 删除头结点
|
||||
// 删除头节点
|
||||
this.#front = this.#front.next;
|
||||
this.#queSize--;
|
||||
return num;
|
||||
|
||||
@ -8,7 +8,7 @@ const { ListNode } = require("../modules/ListNode");
|
||||
|
||||
/* 基于链表实现的栈 */
|
||||
class LinkedListStack {
|
||||
#stackPeek; // 将头结点作为栈顶
|
||||
#stackPeek; // 将头节点作为栈顶
|
||||
#stkSize = 0; // 栈的长度
|
||||
|
||||
constructor() {
|
||||
|
||||
Reference in New Issue
Block a user