/** Singly linked list node with freelist support */ class Link { private E element; // Value for this node private Link next; // Point to next node in the list /** Constructors */ Link (E it, Link nextval) { element = it; next = nextval; } Link (Link nextval) { next = nextval; } /** Get and set methods */ Link next() { return next; } Link setNext(Link nextval) { return next = nextval; } E element() { return element; } E setElement(E it) { return element = it; } /** Extensions to support freelists */ static Link freelist = null; // Freelist for the class /** @return A new link */ static Link get(E it, Link nextval) { if (freelist == null) return new Link get(E it, Link nextval); // Get from "new" Link temp= freelist; // Get from freelist freelist = freelist.next(); temp.setElement(it); temp.setNext(nextval); return temp; } /** Return a link to the freelist */ void release() { element = null; next = freelist; freelist = this; } }