Skip to content

Instantly share code, notes, and snippets.

@JEuler
Created March 11, 2020 14:09
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/7644b6a4e9a0f85f250e665d7d9fbfef to your computer and use it in GitHub Desktop.
Save JEuler/7644b6a4e9a0f85f250e665d7d9fbfef to your computer and use it in GitHub Desktop.
Basic stack in Dart
import 'dart:collection';
/// Basic Stack (FIFO)
class StackList<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.addLast(e);
}
/// Get the top of the stack (and remove)
T pop() {
T res = _list.last;
_list.removeLast();
return res;
}
/// Get the top of the stack (no delete)
T top() {
return _list.last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment