File size: 978 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
package torea;
class Stack{
public static class ListStack<E> implements IStack<E>
{
private Node top = null;
private int size;
private class Node
{
E reference;
Node next;
}
ListStack(){}
@Override
public boolean isEmpty() {
return top == null;
}
@Override
public E pop() {
E item = top.reference;
top = top.next;
size--;
return item;
}
@Override
public E peek() {
return top.reference;
}
@Override
public void push(E item) {
Node old_top = top;
top = new Node();
top.reference = item;
top.next = old_top;
size++;
}
@Override
public int size() {
return size;
}
}
} |