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
@@ -10,7 +10,7 @@ use std::rc::Rc;
use std::cell::RefCell;
use list_node::ListNode;
/* 在链表的点 n0 之后插入点 P */
/* 在链表的点 n0 之后插入点 P */
#[allow(non_snake_case)]
pub fn insert<T>(n0: &Rc<RefCell<ListNode<T>>>, P: Rc<RefCell<ListNode<T>>>) {
let n1 = n0.borrow_mut().next.take();
@@ -18,7 +18,7 @@ pub fn insert<T>(n0: &Rc<RefCell<ListNode<T>>>, P: Rc<RefCell<ListNode<T>>>) {
n0.borrow_mut().next = Some(P);
}
/* 删除链表的点 n0 之后的首个*/
/* 删除链表的点 n0 之后的首个*/
#[allow(non_snake_case)]
pub fn remove<T>(n0: &Rc<RefCell<ListNode<T>>>) {
if n0.borrow().next.is_none() {return};
@@ -30,7 +30,7 @@ pub fn remove<T>(n0: &Rc<RefCell<ListNode<T>>>) {
}
}
/* 访问链表中索引为 index 的*/
/* 访问链表中索引为 index 的*/
pub fn access<T>(head: Rc<RefCell<ListNode<T>>>, index: i32) -> Rc<RefCell<ListNode<T>>> {
if index <= 0 {return head};
if let Some(node) = &head.borrow_mut().next {
@@ -39,7 +39,7 @@ pub fn access<T>(head: Rc<RefCell<ListNode<T>>>, index: i32) -> Rc<RefCell<ListN
return head;
}
/* 在链表中查找值为 target 的首个*/
/* 在链表中查找值为 target 的首个*/
pub fn find<T: PartialEq>(head: Rc<RefCell<ListNode<T>>>, target: T, index: i32) -> i32 {
if head.borrow().val == target {return index};
if let Some(node) = &head.borrow_mut().next {
@@ -51,7 +51,7 @@ pub fn find<T: PartialEq>(head: Rc<RefCell<ListNode<T>>>, target: T, index: i32)
/* Driver Code */
fn main() {
/* 初始化链表 */
// 初始化各个
// 初始化各个
let n0 = ListNode::new(1);
let n1 = ListNode::new(3);
let n2 = ListNode::new(2);
@@ -65,21 +65,21 @@ fn main() {
print!("初始化的链表为 ");
print_util::print_linked_list(&n0);
/* 插入*/
/* 插入*/
insert(&n0, ListNode::new(0));
print!("插入点后的链表为 ");
print!("插入点后的链表为 ");
print_util::print_linked_list(&n0);
/* 删除*/
/* 删除*/
remove(&n0);
print!("删除点后的链表为 ");
print!("删除点后的链表为 ");
print_util::print_linked_list(&n0);
/* 访问*/
/* 访问*/
let node = access(n0.clone(), 3);
println!("链表中索引 3 处的点的值 = {}", node.borrow().val);
println!("链表中索引 3 处的点的值 = {}", node.borrow().val);
/* 查找*/
/* 查找*/
let index = find(n0.clone(), 2, 0);
println!("链表中值为 2 的点的索引 = {}", index);
println!("链表中值为 2 的点的索引 = {}", index);
}
@@ -9,11 +9,11 @@ include!("../include/include.rs");
use std::rc::Rc;
use std::cell::RefCell;
/* 双向链表*/
/* 双向链表*/
pub struct ListNode<T> {
pub val: T, // 点值
pub next: Option<Rc<RefCell<ListNode<T>>>>, // 后继点引用(指针)
pub prev: Option<Rc<RefCell<ListNode<T>>>>, // 前驱点引用(指针)
pub val: T, // 点值
pub next: Option<Rc<RefCell<ListNode<T>>>>, // 后继点引用(指针)
pub prev: Option<Rc<RefCell<ListNode<T>>>>, // 前驱点引用(指针)
}
impl<T> ListNode<T> {
@@ -29,8 +29,8 @@ impl<T> ListNode<T> {
/* 基于双向链表实现的双向队列 */
#[allow(dead_code)]
pub struct LinkedListDeque<T> {
front: Option<Rc<RefCell<ListNode<T>>>>, // 头点 front
rear: Option<Rc<RefCell<ListNode<T>>>>, // 尾点 rear
front: Option<Rc<RefCell<ListNode<T>>>>, // 头点 front
rear: Option<Rc<RefCell<ListNode<T>>>>, // 尾点 rear
que_size: usize, // 双向队列的长度
}
@@ -63,7 +63,7 @@ impl<T: Copy> LinkedListDeque<T> {
Some(old_front) => {
old_front.borrow_mut().prev = Some(node.clone());
node.borrow_mut().next = Some(old_front);
self.front = Some(node); // 更新头
self.front = Some(node); // 更新头
}
None => {
self.rear = Some(node.clone());
@@ -77,7 +77,7 @@ impl<T: Copy> LinkedListDeque<T> {
Some(old_rear) => {
old_rear.borrow_mut().next = Some(node.clone());
node.borrow_mut().prev = Some(old_rear);
self.rear = Some(node); // 更新尾
self.rear = Some(node); // 更新尾
}
None => {
self.front = Some(node.clone());
@@ -107,7 +107,7 @@ impl<T: Copy> LinkedListDeque<T> {
match old_front.borrow_mut().next.take() {
Some(new_front) => {
new_front.borrow_mut().prev.take();
self.front = Some(new_front); // 更新头
self.front = Some(new_front); // 更新头
}
None => {
self.rear.take();
@@ -122,7 +122,7 @@ impl<T: Copy> LinkedListDeque<T> {
match old_rear.borrow_mut().prev.take() {
Some(new_rear) => {
new_rear.borrow_mut().next.take();
self.rear = Some(new_rear); // 更新尾
self.rear = Some(new_rear); // 更新尾
}
None => {
self.front.take();
@@ -13,8 +13,8 @@ use list_node::ListNode;
/* 基于链表实现的队列 */
#[allow(dead_code)]
pub struct LinkedListQueue<T> {
front: Option<Rc<RefCell<ListNode<T>>>>, // 头点 front
rear: Option<Rc<RefCell<ListNode<T>>>>, // 尾点 rear
front: Option<Rc<RefCell<ListNode<T>>>>, // 头点 front
rear: Option<Rc<RefCell<ListNode<T>>>>, // 尾点 rear
que_size: usize, // 队列的长度
}
@@ -39,15 +39,15 @@ impl<T: Copy> LinkedListQueue<T> {
/* 入队 */
pub fn push(&mut self, num: T) {
// 尾点后添加 num
// 尾点后添加 num
let new_rear = ListNode::new(num);
match self.rear.take() {
// 如果队列不为空,则将该点添加到尾点后
// 如果队列不为空,则将该点添加到尾点后
Some(old_rear) => {
old_rear.borrow_mut().next = Some(new_rear.clone());
self.rear = Some(new_rear);
}
// 如果队列为空,则令头、尾点都指向该
// 如果队列为空,则令头、尾点都指向该
None => {
self.front = Some(new_rear.clone());
self.rear = Some(new_rear);
@@ -13,7 +13,7 @@ use list_node::ListNode;
/* 基于链表实现的栈 */
#[allow(dead_code)]
pub struct LinkedListStack<T> {
stack_peek: Option<Rc<RefCell<ListNode<T>>>>, // 将头点作为栈顶
stack_peek: Option<Rc<RefCell<ListNode<T>>>>, // 将头点作为栈顶
stk_size: usize, // 栈的长度
}
+5 -5
View File
@@ -24,16 +24,16 @@ fn main() {
println!("\n初始化二叉树\n");
print_util::print_tree(&n1);
// 插入点与删除
// 插入点与删除
let p = TreeNode::new(0);
// 在 n1 -> n2 中间插入点 P
// 在 n1 -> n2 中间插入点 P
p.borrow_mut().left = Some(Rc::clone(&n2));
n1.borrow_mut().left = Some(Rc::clone(&p));
println!("\n插入点 P 后\n");
println!("\n插入点 P 后\n");
print_util::print_tree(&n1);
// 删除点 P
// 删除点 P
drop(p);
n1.borrow_mut().left = Some(Rc::clone(&n2));
println!("\n删除点 P 后\n");
println!("\n删除点 P 后\n");
print_util::print_tree(&n1);
}