Skip to content

Commit

Permalink
stack: Update impl of stack
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Aug 1, 2024
1 parent 1b5a845 commit bd1650e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/stack/assets/vec_stack.rs
2 changes: 2 additions & 0 deletions src/stack/basic-ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

![stack push](assets/stack-push.svg)

如果是动态栈, 不受容量限制, 那这个函数就没有返回值, 也不存在栈满的问题.

## 出栈 pop()

元素出栈顺序跟其入栈顺序是相反的.
Expand Down
12 changes: 11 additions & 1 deletion src/stack/impl-of-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@

## 使用动态数组 Vec 实现动态栈

## 使用链表实现动态栈
使用 `Vec<T>` 实现的栈可以进行动态扩容, 但每次扩容时可能要进行内存的批量拷贝.

这个比较简单, 因为 `Vec<T>` 本身就实现了基本的栈操作接口, 我们只需要再包装一下就行:

```rust
{{#include assets/vec_stack.rs:5:70}}
```

## 使用链表实现动态栈

TODO(Shaohua):

0 comments on commit bd1650e

Please sign in to comment.