Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stack<T> {
- private Node<T> first;
- //creates an empty stack
- public Stack() {
- this.first = first;
- }
- //returns true if stack is empty
- public boolean isEmpty() {
- return this.first == null;
- }
- //push value into stack - Last In First Out
- public void push(T x) {
- this.first = new Node<T>(x, this.first);
- }
- //extract the toped value of stacked - Last In First Out
- public T pop() {
- T x = this.first.getValue();
- this.first = this.first.getNext();
- return x;
- }
- //returns the value in the top without extracting him
- public T top() {
- return this.first.getValue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement