Doubly linked list,
Doubly linked list needs to add a previous property
/*doubly linked list **/functionNode (Element) { This. Element =element; This. Next =NULL; This. Previous =NULL;//the doubly linked list here needs to add a previous property}functionllist () { This. Head =NewNode ("Head"); This. Find =find; This. Insert =Insert; This. display =display; This. remove =remove; This. FindLast =FindLast; This. Dispreverse = Dispreverse;//invert a linked list}functionDispreverse () {varCurrnode = This. Head; Currnode= This. FindLast (); varNodestr = ""; while(! (Currnode.previous = =NULL) ) {Nodestr+= " "+currnode.element; Currnode=currnode.previous; } console.log ("Invert the list after:" +nodestr);}functionFindLast () {varCurrnode = This. Head; while(! (Currnode.next = =NULL) ) {Currnode=Currnode.next; } returnCurrnode;}functionRemove (item) {varCurrnode = This. Find (item); if(! (Currnode.next = =NULL) ) {CurrNode.previous.next=Currnode.next; CurrNode.next.previous=currnode.previous; Currnode.next=NULL; Currnode.previous=NULL; }}//findprevious is no longer needed/*function FindPrevious (item) {var currnode = This.head; Currnode.next = = null) && (currNode.next.element = Item) {Currnode = Currnode.next;} return currnode; }*/functiondisplay () {varCurrnode = This. Head; varNodestr = ""; while(! (Currnode.next = =NULL) ) {Nodestr+= " "+currNode.next.element; Currnode=Currnode.next; } console.log (NODESTR);}functionFind (item) {varCurrnode = This. Head; while(Currnode.element! =Item) {Currnode=Currnode.next; } returnCurrnode;}functionInsert (newelement, item) {varNewNode =NewNode (newelement); varCurrent = This. Find (item); Newnode.next=Current.next; Newnode.previous= current;//the doubly linked list here needs to set the new node previous propertyCurrent.next =NewNode;}varCities =Newllist (); Cities.insert ("Conway", "head"); Cities.insert ("Russellville", "Conway"); Cities.insert ("Carlisle", "Russellville"); Cities.insert ("Alma", "Carlisle"); Cities.display ();//Conway Russellville Carlisle AlmaCities.remove ("Carlisle"); Cities.display ();//Conway Russellville AlmaCities.dispreverse ();//Alma Russellville Conway
JS to implement a doubly linked list, doubly linked list needs to add a previous property