Skip to content

Instantly share code, notes, and snippets.

@JEuler
Created March 15, 2020 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JEuler/749702353fa9363538629fa6a2d6ef2f to your computer and use it in GitHub Desktop.
Save JEuler/749702353fa9363538629fa6a2d6ef2f to your computer and use it in GitHub Desktop.
Basic queue in Dart
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