Created
March 11, 2020 14:09
-
-
Save JEuler/7644b6a4e9a0f85f250e665d7d9fbfef to your computer and use it in GitHub Desktop.
Basic stack 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 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