Skip to content

Instantly share code, notes, and snippets.

@njofce
Created August 5, 2019 14:08
Show Gist options
  • Save njofce/54b801fb0500e57c6fc17a7289162989 to your computer and use it in GitHub Desktop.
Save njofce/54b801fb0500e57c6fc17a7289162989 to your computer and use it in GitHub Desktop.
class QueueStack<T> {
private List<T> dataCollection;
QueueStack() {
dataCollection = new LinkedList<>();
}
void push(T item) {
dataCollection.add(0, item);
}
Optional<T> pop() {
if(dataCollection.size() > 0)
return Optional.of(dataCollection.remove(dataCollection.size() - 1));
else
return Optional.empty();
}
void clear() {
dataCollection.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment