|
|
@ -9,13 +9,9 @@ import 'dart:collection';
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
/* 初始化双向队列 */
|
|
|
|
/* 初始化双向队列 */
|
|
|
|
final Queue<int> deque = Queue();
|
|
|
|
final Queue<int> deque = Queue();
|
|
|
|
|
|
|
|
deque.addFirst(3);
|
|
|
|
/* 元素入队 */
|
|
|
|
|
|
|
|
deque.addLast(2);
|
|
|
|
deque.addLast(2);
|
|
|
|
deque.addLast(5);
|
|
|
|
deque.addLast(5);
|
|
|
|
deque.addLast(4);
|
|
|
|
|
|
|
|
deque.addFirst(3);
|
|
|
|
|
|
|
|
deque.addFirst(1);
|
|
|
|
|
|
|
|
print("双向队列 deque = $deque");
|
|
|
|
print("双向队列 deque = $deque");
|
|
|
|
|
|
|
|
|
|
|
|
/* 访问元素 */
|
|
|
|
/* 访问元素 */
|
|
|
@ -24,17 +20,24 @@ void main() {
|
|
|
|
final int peekLast = deque.last;
|
|
|
|
final int peekLast = deque.last;
|
|
|
|
print("队尾元素 peekLast = $peekLast");
|
|
|
|
print("队尾元素 peekLast = $peekLast");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 元素入队 */
|
|
|
|
|
|
|
|
deque.addLast(4);
|
|
|
|
|
|
|
|
print("元素 4 队尾入队后 deque = $deque");
|
|
|
|
|
|
|
|
deque.addFirst(1);
|
|
|
|
|
|
|
|
print("元素 1 队首入队后 deque = $deque");
|
|
|
|
|
|
|
|
|
|
|
|
/* 元素出队 */
|
|
|
|
/* 元素出队 */
|
|
|
|
final int popFirst = deque.removeFirst();
|
|
|
|
|
|
|
|
print("队首出队元素 popFirst = $popFirst,队首出队后 deque = $deque");
|
|
|
|
|
|
|
|
final int popLast = deque.removeLast();
|
|
|
|
final int popLast = deque.removeLast();
|
|
|
|
print("队尾出队元素 popLast = $popLast,队尾出队后 deque = $deque");
|
|
|
|
print("队尾出队元素 = $popLast,队尾出队后 deque = $deque");
|
|
|
|
|
|
|
|
final int popFirst = deque.removeFirst();
|
|
|
|
|
|
|
|
print("队首出队元素 = $popFirst,队首出队后 deque = $deque");
|
|
|
|
|
|
|
|
|
|
|
|
/* 获取双向队列的长度 */
|
|
|
|
/* 获取双向队列的长度 */
|
|
|
|
final int size = deque.length;
|
|
|
|
final int size = deque.length;
|
|
|
|
print("双向队列的长度 size = $size");
|
|
|
|
print("双向队列长度 size = $size");
|
|
|
|
|
|
|
|
|
|
|
|
/* 判断双向队列是否为空 */
|
|
|
|
/* 判断双向队列是否为空 */
|
|
|
|
final bool isEmpty = deque.isEmpty;
|
|
|
|
final bool isEmpty = deque.isEmpty;
|
|
|
|
print("双向队列是否为空 isEmpty = $isEmpty");
|
|
|
|
print("双向队列是否为空 = $isEmpty");
|
|
|
|
}
|
|
|
|
}
|
|
|
|