prepare to search for the insertion point by setting current to first in the usual way we also set previous to nullthis step is important because later we'll use this null value to determine whether we're still at the beginning of the list the while loop is similar to those we've used before to search for the insertion pointbut there' an added condition the loop terminates when the key of the link currently being examined (current ddatais no longer smaller than the key of the link being inserted (key)this is the most usual casewhere key is inserted somewhere in the middle of the list howeverthe while loop also terminates if current is null this happens at the end of the list (the next field of the last element is null)or if the list is empty to begin with (first is nullwhen the while loop terminatesthenwe may be at the beginningthe middleor the end of the listor the list may be empty if we're at the beginningor the list is emptyprevious will be nullso we set first to the new link otherwisewe're in the middle of the listor at the endand we set previous next to the new link in any case we set the new link' next field to current if we're at the end of the listcurrent is nullso the new link' next field is appropriately set to this value the sortedlist java program the sortedlist java example shown in listing presents sortedlist class with insert()remove()and displaylist(methods only the insert(routine is different from its counterpart in non-sorted lists listing the sortedlist java program /sortedlist java /demonstrates sorted list /to run this programc>java sortedlistapp ///////////////////////////////////////////////////////////////class link public long ddata/data item public link next/next link in list /public link(long dd/constructor ddata dd/public void displaylink(/display this link system out print(ddata ")