mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-10 06:05:35 +08:00
build
This commit is contained in:
@@ -1679,7 +1679,7 @@ comments: true
|
||||
}
|
||||
}
|
||||
self.que_size -= 1; // 更新队列长度
|
||||
Rc::try_unwrap(old_front).ok().unwrap().into_inner().val
|
||||
old_front.borrow().val
|
||||
})
|
||||
}
|
||||
// 队尾出队操作
|
||||
@@ -1695,7 +1695,7 @@ comments: true
|
||||
}
|
||||
}
|
||||
self.que_size -= 1; // 更新队列长度
|
||||
Rc::try_unwrap(old_rear).ok().unwrap().into_inner().val
|
||||
old_rear.borrow().val
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1722,12 +1722,16 @@ comments: true
|
||||
|
||||
/* 返回数组用于打印 */
|
||||
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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1070,7 +1070,7 @@ comments: true
|
||||
}
|
||||
}
|
||||
self.que_size -= 1;
|
||||
Rc::try_unwrap(old_front).ok().unwrap().into_inner().val
|
||||
old_front.borrow().val
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1081,12 +1081,18 @@ comments: true
|
||||
|
||||
/* 将链表转化为 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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -964,16 +964,10 @@ comments: true
|
||||
/* 出栈 */
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user