mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 18:00:18 +08:00
build
This commit is contained in:
@@ -292,7 +292,30 @@ comments: true
|
||||
=== "Dart"
|
||||
|
||||
```dart title="deque.dart"
|
||||
/* 初始化双向队列 */
|
||||
// 在 Dart 中,Queue 被定义为双向队列
|
||||
Queue<int> deque = Queue<int>();
|
||||
|
||||
/* 元素入队 */
|
||||
deque.addLast(2); // 添加至队尾
|
||||
deque.addLast(5);
|
||||
deque.addLast(4);
|
||||
deque.addFirst(3); // 添加至队首
|
||||
deque.addFirst(1);
|
||||
|
||||
/* 访问元素 */
|
||||
int peekFirst = deque.first; // 队首元素
|
||||
int peekLast = deque.last; // 队尾元素
|
||||
|
||||
/* 元素出队 */
|
||||
int popFirst = deque.removeFirst(); // 队首元素出队
|
||||
int popLast = deque.removeLast(); // 队尾元素出队
|
||||
|
||||
/* 获取双向队列的长度 */
|
||||
int size = deque.length;
|
||||
|
||||
/* 判断双向队列是否为空 */
|
||||
bool isEmpty = deque.isEmpty;W
|
||||
```
|
||||
|
||||
## 5.3.2. 双向队列实现 *
|
||||
|
||||
Reference in New Issue
Block a user