linked lists figure newly inserted link when the algorithm finds where to put itthe item can be inserted in the usual way by changing next in the new link to point to the next link and changing next in the previous link to point to the new link howeverwe need to consider some special casesthe link might need to be inserted at the beginning of the listor it might need to go at the end let' look at the codepublic void insert(long key/insert in order link newlink new link(key)/make new link link previous null/start at first link current first/until end of listwhile(current !null &key current ddata/or key currentprevious currentcurrent current next/go to next item if(previous==null/at beginning of list first newlink/first --newlink else /not at beginning previous next newlink/old prev --newlink newlink next current/newlink --old current /end insert(we need to maintain previous reference as we move alongso we can modify the previous link' next field to point to the new link after creating the new linkwe