Created
August 5, 2019 14:08
-
-
Save njofce/54b801fb0500e57c6fc17a7289162989 to your computer and use it in GitHub Desktop.
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
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