/* * Single-linked implementation * with count and private class List */ package stackl; //stack implemented as list //the topmost element of stack is head //the body of the stack is tail /** * * @author suchenek */ public class Stack { private class List { protected Object head; protected List tail; } private List stack; //so that count does not occur in substacks private int count; public void makenull() { stack = null; count = 0; } public void push(Object newItem) { List temp = new List(); temp.head = newItem; temp.tail = this.stack; this.stack = temp; count++; } public Object pop() { if (stack == null) return null; Object toReturn; toReturn = stack.head; stack = stack.tail; count--; return toReturn; } public int size() { return count; } public boolean isEmpty() { return stack == null; } public int Length() { return 0; } }