feat: modify some Dart codes and add Dart code blocks to the docs (#543)

This commit is contained in:
liuyuxin
2023-06-02 14:56:29 +08:00
committed by GitHub
parent 53e18bc6d6
commit 281c0c618a
25 changed files with 339 additions and 54 deletions

View File

@@ -253,7 +253,28 @@
=== "Dart"
```dart title="stack.dart"
/* 初始化栈 */
// Dart 没有内置的栈类,可以把 List 当作栈来使用
List<int> stack = [];
/* 元素入栈 */
stack.add(1);
stack.add(3);
stack.add(2);
stack.add(5);
stack.add(4);
/* 访问栈顶元素 */
int peek = stack.last;
/* 元素出栈 */
int pop = stack.removeLast();
/* 获取栈的长度 */
int size = stack.length;
/* 判断是否为空 */
bool isEmpty = stack.isEmpty;
```
## 栈的实现