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:
Yudong Jin
2023-04-09 04:32:17 +08:00
committed by GitHub
parent 3f4e32b2b0
commit 1c8b7ef559
395 changed files with 2056 additions and 2056 deletions

View File

@@ -5,14 +5,14 @@
const std = @import("std");
const inc = @import("include");
// 双向链表
// 双向链表
pub fn ListNode(comptime T: type) type {
return struct {
const Self = @This();
val: T = undefined, // 点值
next: ?*Self = null, // 后继点引用(指针)
prev: ?*Self = null, // 前驱点引用(指针)
val: T = undefined, // 点值
next: ?*Self = null, // 后继点引用(指针)
prev: ?*Self = null, // 前驱点引用(指针)
// Initialize a list node with specific value
pub fn init(self: *Self, x: i32) void {
@@ -28,8 +28,8 @@ pub fn LinkedListDeque(comptime T: type) type {
return struct {
const Self = @This();
front: ?*ListNode(T) = null, // 头点 front
rear: ?*ListNode(T) = null, // 尾点 rear
front: ?*ListNode(T) = null, // 头点 front
rear: ?*ListNode(T) = null, // 尾点 rear
que_size: usize = 0, // 双向队列的长度
mem_arena: ?std.heap.ArenaAllocator = null,
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
@@ -74,13 +74,13 @@ pub fn LinkedListDeque(comptime T: type) type {
// 将 node 添加至链表头部
self.front.?.prev = node;
node.next = self.front;
self.front = node; // 更新头
self.front = node; // 更新头
// 队尾入队操作
} else {
// 将 node 添加至链表尾部
self.rear.?.next = node;
node.prev = self.rear;
self.rear = node; // 更新尾
self.rear = node; // 更新尾
}
self.que_size += 1; // 更新队列长度
}
@@ -101,24 +101,24 @@ pub fn LinkedListDeque(comptime T: type) type {
var val: T = undefined;
// 队首出队操作
if (is_front) {
val = self.front.?.val; // 暂存头点值
// 删除头
val = self.front.?.val; // 暂存头点值
// 删除头
var fNext = self.front.?.next;
if (fNext != null) {
fNext.?.prev = null;
self.front.?.next = null;
}
self.front = fNext; // 更新头
self.front = fNext; // 更新头
// 队尾出队操作
} else {
val = self.rear.?.val; // 暂存尾点值
// 删除尾
val = self.rear.?.val; // 暂存尾点值
// 删除尾
var rPrev = self.rear.?.prev;
if (rPrev != null) {
rPrev.?.next = null;
self.rear.?.prev = null;
}
self.rear = rPrev; // 更新尾
self.rear = rPrev; // 更新尾
}
self.que_size -= 1; // 更新队列长度
return val;

View File

@@ -10,8 +10,8 @@ pub fn LinkedListQueue(comptime T: type) type {
return struct {
const Self = @This();
front: ?*inc.ListNode(T) = null, // 头点 front
rear: ?*inc.ListNode(T) = null, // 尾点 rear
front: ?*inc.ListNode(T) = null, // 头点 front
rear: ?*inc.ListNode(T) = null, // 尾点 rear
que_size: usize = 0, // 队列的长度
mem_arena: ?std.heap.ArenaAllocator = null,
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
@@ -51,14 +51,14 @@ pub fn LinkedListQueue(comptime T: type) type {
// 入队
pub fn push(self: *Self, num: T) !void {
// 尾点后添加 num
// 尾点后添加 num
var node = try self.mem_allocator.create(inc.ListNode(T));
node.init(num);
// 如果队列为空,则令头、尾点都指向该
// 如果队列为空,则令头、尾点都指向该
if (self.front == null) {
self.front = node;
self.rear = node;
// 如果队列不为空,则将该点添加到尾点后
// 如果队列不为空,则将该点添加到尾点后
} else {
self.rear.?.next = node;
self.rear = node;
@@ -69,7 +69,7 @@ pub fn LinkedListQueue(comptime T: type) type {
// 出队
pub fn pop(self: *Self) T {
var num = self.peek();
// 删除头
// 删除头
self.front = self.front.?.next;
self.que_size -= 1;
return num;

View File

@@ -10,7 +10,7 @@ pub fn LinkedListStack(comptime T: type) type {
return struct {
const Self = @This();
stack_top: ?*inc.ListNode(T) = null, // 将头点作为栈顶
stack_top: ?*inc.ListNode(T) = null, // 将头点作为栈顶
stk_size: usize = 0, // 栈的长度
mem_arena: ?std.heap.ArenaAllocator = null,
mem_allocator: std.mem.Allocator = undefined, // 内存分配器