Bug fixes and improvements (#1732)

* Bug fixes

* Sync zh and zh-hant versions.

* "入列列" -> "入佇列"

* Fix hello_algo_mindmap.png
This commit is contained in:
Yudong Jin
2025-04-10 19:21:52 +08:00
committed by GitHub
parent a9d44c3a25
commit 8e38c61455
14 changed files with 48 additions and 49 deletions
@@ -120,7 +120,7 @@ impl<T: Copy> LinkedListDeque<T> {
}
}
self.que_size -= 1; // 更新佇列長度
Rc::try_unwrap(old_front).ok().unwrap().into_inner().val
old_front.borrow().val
})
}
// 佇列尾出列操作
@@ -136,7 +136,7 @@ impl<T: Copy> LinkedListDeque<T> {
}
}
self.que_size -= 1; // 更新佇列長度
Rc::try_unwrap(old_rear).ok().unwrap().into_inner().val
old_rear.borrow().val
})
}
}
@@ -163,12 +163,16 @@ impl<T: Copy> LinkedListDeque<T> {
/* 返回陣列用於列印 */
pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {
if let Some(node) = head {
let mut nums = self.to_array(node.borrow().next.as_ref());
nums.insert(0, node.borrow().val);
return nums;
let mut res: Vec<T> = Vec::new();
fn recur<T: Copy>(cur: Option<&Rc<RefCell<ListNode<T>>>>, res: &mut Vec<T>) {
if let Some(cur) = cur {
res.push(cur.borrow().val);
recur(cur.borrow().next.as_ref(), res);
}
}
return Vec::new();
recur(head, &mut res);
res
}
}
@@ -67,7 +67,7 @@ impl<T: Copy> LinkedListQueue<T> {
}
}
self.que_size -= 1;
Rc::try_unwrap(old_front).ok().unwrap().into_inner().val
old_front.borrow().val
})
}
@@ -78,12 +78,18 @@ impl<T: Copy> LinkedListQueue<T> {
/* 將鏈結串列轉化為 Array 並返回 */
pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {
if let Some(node) = head {
let mut nums = self.to_array(node.borrow().next.as_ref());
nums.insert(0, node.borrow().val);
return nums;
let mut res: Vec<T> = Vec::new();
fn recur<T: Copy>(cur: Option<&Rc<RefCell<ListNode<T>>>>, res: &mut Vec<T>) {
if let Some(cur) = cur {
res.push(cur.borrow().val);
recur(cur.borrow().next.as_ref(), res);
}
}
return Vec::new();
recur(head, &mut res);
res
}
}
@@ -45,16 +45,10 @@ impl<T: Copy> LinkedListStack<T> {
/* 出堆疊 */
pub fn pop(&mut self) -> Option<T> {
self.stack_peek.take().map(|old_head| {
match old_head.borrow_mut().next.take() {
Some(new_head) => {
self.stack_peek = Some(new_head);
}
None => {
self.stack_peek = None;
}
}
self.stack_peek = old_head.borrow_mut().next.take();
self.stk_size -= 1;
Rc::try_unwrap(old_head).ok().unwrap().into_inner().val
old_head.borrow().val
})
}