public class List5 { private Node5 head; public List5 () //constructor { head = null; } //********************************************************** public void Initialize(E dummy) // draw a diagram showing what this does { head = new Node5(dummy); head.next = head; head.prev = head; } //********************************************************** public void Insert(E element) // draw how this inserts { Node5 current = new Node5(element); current.next = head; current.prev = head.prev; head.prev.next = current; head.prev = current; } //************************************************************* public String toString() // prints out the entire list between square brackets { StringBuffer s = new StringBuffer(""); //put elements into the buffer Node5 current = head; if (current.next != null) current = current.next; while (!(current.item.equals("*"))) { s.append(current.item.toString() + "\n"); current = current.next; } return new String(s); } //********************************************************** public int myCompare(E one, E two) //compare { String stringOne = (String)one; //cast to String type to use compareTo String stringTwo = (String)two; return stringOne.compareTo(stringTwo); //return value of compare } //********************************************************* /* this is an inner class so its data members can be accessed directory*/ private class Node5 { // instance variables private E item; private Node5 prev; private Node5 next; // two constructors to initialise instance variables private Node5(E i) { item = i; prev = null; next = null; } private Node5(E i, Node5 p, Node5 n) { item = i; prev = p; next = n; } } }