mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 03:30:30 +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:
@@ -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, // 栈的长度
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user