hello-algo/codes/dart/chapter_stack_and_queue/queue.dart
liuyuxin 684f27cf5e
feat: add dart code for chapter_stack_and_queue and chapter_hashing (#445)
* feat: add dart code for chapter stack and queue

* feat: add dart code for chapter_hashing

* Update array_hash_map.dart
2023-03-30 02:03:08 +08:00

37 lines
857 B
Dart

/**
* File: queue:dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
import 'dart:collection';
void main() {
/* 初始化队列 */
// 在 Dart 中,一般将双向队列类 Queue 看作队列使用
final Queue<int> queue = Queue();
/* 元素入队 */
queue.add(1);
queue.add(3);
queue.add(2);
queue.add(5);
queue.add(4);
print("队列 queue = $queue");
/* 访问队首元素 */
final int peek = queue.first;
print("队首元素 peek = $peek");
/* 元素出队 */
final int pop = queue.removeFirst();
print("出队元素 pop = $pop,出队后队列 queue = $queue");
/* 获取队列长度 */
final int size = queue.length;
print("队列长度 size = $size");
/* 判断队列是否为空 */
final bool isEmpty = queue.isEmpty;
print("队列是否为空 isEmpty = $isEmpty");
}