// listInsertionSort.java // demonstrates sorted list used for sorting // to run this program: C>java ListInsertionSortApp //////////////////////////////////////////////////////////////// class Link { public long dData; // data item public Link next; // next link in list // ------------------------------------------------------------- public Link(long dd) // constructor { dData = dd; } // ------------------------------------------------------------- } // end class Link //////////////////////////////////////////////////////////////// class SortedList { private Link first; // ref to first item on list // ------------------------------------------------------------- public SortedList() // constructor (no args) { first = null; } // initialize list // ------------------------------------------------------------- public SortedList(Link[] linkArr) // constructor (array { // as argument) first = null; // initialize list for(int j=0; j current.dData) { // or key > current, previous = current; current = current.next; // go to next item } if(previous==null) // at beginning of list first = k; // first --> k else // not at beginning previous.next = k; // old prev --> k k.next = current; // k --> old currnt } // end insert() // ------------------------------------------------------------- public Link remove() // return & delete first link { // (assumes non-empty list) Link temp = first; // save first first = first.next; // delete first return temp; // return value } // ------------------------------------------------------------- } // end class SortedList //////////////////////////////////////////////////////////////// class ListInsertionSortApp { public static void main(String[] args) { int size = 10; // create array of links Link[] linkArray = new Link[size]; for(int j=0; j