/** Singly linked list node */ class Link { private T element; // Value for this node private Link next; // Pointer to next node in list // Constructors Link(T it, Link nextVal) { element = it; next = nextVal; } Link(Link nextVal) { next = nextVal; } Link next() {return next; } // Return nrxt field Link setNext(Link nextVal) // Set next field { return next = nextVal; } // Return element field T element() { return element; } // Set element field T setElement(T it) { return element = it; } /** Extensions to support freelists */ static Link freelist = null; // Freelist for the class /** @return A new link */ static Link get(Tit, Link nextVal) { if (freelist == null) return new Link(it, 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; // Drop reference to the element next = freelist; freelist = this; } }