Created
March 15, 2020 12:56
-
-
Save JEuler/749702353fa9363538629fa6a2d6ef2f to your computer and use it in GitHub Desktop.
Basic queue in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:collection'; | |
/// Basic Queue (LIFO) | |
class QueueList<T> { | |
final ListQueue<T> _list = ListQueue(); | |
/// Is empty? | |
bool get isEmpty => _list.isEmpty; | |
/// Not empty? | |
bool get isNotEmpty => _list.isNotEmpty; | |
/// Put element on top | |
void push(T e) { | |
_list.addFirst(e); | |
} | |
/// Get the top of the queue (and remove) | |
T pop() { | |
final res = _list.first; | |
_list.removeFirst(); | |
return res; | |
} | |
/// Get the top of the queue (no delete) | |
T top() { | |
return _list.first; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment