//The following is a linked list class
function LinkedList(){
//Node represents the item to be added to the list
var Node=function(element){
<br/>
this.element=element;
this.next= null;
};
var length=0;//Storage the number of list items
var head=null;//head stores a reference to the first node
//Append elements to the end of the linked list
this. append=function(element){
var node=new Node(element),
current;
if(head===null){
head=node;
}else{
current=node;
while( current.next){
current=current.next;
}
current.next=node;
}
length++;
};
//Insert an element at any position in the linked list
this.insert=function (position,element){
if(position>=0&&position<=length){<br/><br/> var node=new Node(element),<br/> current=head,<br/> previous,<br/> index=0;<br/><br/> if(position=== 0){<br/> node.next=current;<br/> head=node;<br/><br/> }else{<br/> while(index
previous,
index=0;
if(position===0){
head=current.next;
} else{
return this.removeAt(index);
};
//Judge whether the linked list is empty
this .isEmpty=function(){
Return length===0;
};
//Return the length of the linked list
this.size=function(){
return length;
};
//Convert the LinkedList object into a string
var current=head,
string="";
while(current){
string=current.element;
}
return string;};
};
var list=new LinkedList();
list.append(15);
list.append(10);
list.insert(1,11);
console.log(list.size());