mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 10:14:44 +08:00
build
This commit is contained in:
@ -876,8 +876,8 @@ Below is an example code for implementing a stack based on a linked list:
|
||||
/* 基于链表实现的栈 */
|
||||
#[allow(dead_code)]
|
||||
pub struct LinkedListStack<T> {
|
||||
stack_peek: Option<Rc<RefCell<ListNode<T>>>>, // 将头节点作为栈顶
|
||||
stk_size: usize, // 栈的长度
|
||||
stack_peek: Option<Rc<RefCell<ListNode<T>>>>, // 将头节点作为栈顶
|
||||
stk_size: usize, // 栈的长度
|
||||
}
|
||||
|
||||
impl<T: Copy> LinkedListStack<T> {
|
||||
@ -1537,7 +1537,9 @@ Since the elements to be pushed onto the stack may continuously increase, we can
|
||||
impl<T> ArrayStack<T> {
|
||||
/* 初始化栈 */
|
||||
fn new() -> ArrayStack<T> {
|
||||
ArrayStack::<T> { stack: Vec::<T>::new() }
|
||||
ArrayStack::<T> {
|
||||
stack: Vec::<T>::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/* 获取栈的长度 */
|
||||
@ -1565,7 +1567,9 @@ Since the elements to be pushed onto the stack may continuously increase, we can
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
fn peek(&self) -> Option<&T> {
|
||||
if self.is_empty() { panic!("栈为空") };
|
||||
if self.is_empty() {
|
||||
panic!("栈为空")
|
||||
};
|
||||
self.stack.last()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user