Write code is really cautious ah, each step of the sequence of operations are in the card.
I actually just understood the thought and the approximate operation.
When you really want to, you might want to copy, paste ... :)
functionLinkedList () {varNode =function(Element) { This. Element =element; This. Next =NULL; }; varLength = 0; varHead =NULL; This. Append =function(Element) {varnode =NewNode (element), current; if(Head = =NULL) {Head=node; } Else{ Current=Head; while(current.next) { current=Current.next; } Current.next=node; } length++; }; This. Insert =function(position, Element) {if(Position >=0 && position <=length) { varnode =NewNode (Element), current=Head, Previous, index=0; if(Position = = 0) {Node.next=Current ; Head=node; } Else { while(Index++ <position) {Previous=Current ; Current=Current.next; } Node.next=Current ; Previous.next=node; } length++; return true; } Else { return false; } }; This. removeAt =function(position) {if(Position >-1 && position <length) { varCurrent =Head, Previous, index= 0; if(Position = = 0) {Head=Current.next; } Else { while(Index++ <position) {Previous=Current ; Current=Current.next; } Previous.next=Current.next; } length--; returncurrent.element; } Else { return NULL; } }; This. remove =function(Element) {varindex = This. IndexOf (Element); return This. removeAt (index); }; This. indexOf =function(Element) {varCurrent =Head, Index=-1; while(current) {if(element = =current.element) { returnindex; } Index++; Current=Current.next; } return-1; }; This. IsEmpty =function(){ returnLength = = 0; }; This. Size =function () { returnlength; }; This. toString =function(){ varCurrent =Head, String= ' '; while(current) {string+=current.element; Current=Current.next; } returnstring; }; This. GetHead =function(){ returnHead; } This. Print =function(){ };}varList =NewLinkedList (); List.append (15); List.append (10); Console.log (list.tostring ());functiondoublylinkedlist () {varNode =function(Element) { This. Element =element; This. Next =NULL; This. prev =NULL; }; varLength = 0; varHead =NULL; varTail =NULL; This. Insert =function(position, Element) {if(Position >=0 && position <=length) { varnode =NewNode (Element), current=Head, Previous, index= 0; if(Position = = 0){ if(!head) {Head=node; Tail=node; } Else{Node.next=Current ; Current.prev=node; Head=node; } } Else if(Position = = =length) { Current=tail; Current.next=node; Node.prev=Current ; Tail=node; } Else { while(Index++ <position) {Previous=Current ; Current=Current.next; } Node.next=Current ; Previous.next=node; Current.prev=node; Node.prev=previous; } length++; return true; } Else { return false; } } This. removeAt =function(position) {if(Position >-1 && position <length) { varCurrent =Head, Previous, index= 0; if(Position = = 0) {Head=Current.next; if(Length = = 1) {Tail=NULL; } Else{Head.prev=NULL; } } Else if(Position = = Length-1) { current=tail; Tail=Current.prev; Tail.next=NULL; } Else { while(Index++ <position) {Previous=Current ; Current=Current.next; } Previous.next=Current.next; Current.next.prev=previous; } length--; returncurrent.element; } Else { return NULL; } }}
JavaScript common linked list and doubly linked list