This commit is contained in:
krahets
2025-03-20 22:54:57 +08:00
parent e81bc45c43
commit 5286e8bbc2
11 changed files with 79 additions and 78 deletions
+11 -7
View File
@@ -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
}
}
```