Linked list
JavaScript
function Node(val){
this.value= val;
this.next;
}
var node1= new Node(5);
var node2= new Node(12);
var node3= new Node(45);
var node4= new Node(56);
var node5= new Node(77);
node1.next= node2;
node2.next= node3;
node3.next= node4;
node4.next= node5;
console.log("node1",node1);
function iterate(node){
while(node1.next){
console.log(node1.value);
node1=node1.next;
if(!node1.next){
console.log(node1.value);
}
}
}
iterate(node1)
function add(nv){
this.length = 0;
this.head = null;
var node = new Node(nv);
currentNode = node1;
console.log("currentNode",currentNode);
if(!currentNode){
this.head= node;
this.length++;
return node
}
while(currentNode.next){
currentNode= currentNode.next;
}
currentNode.next = node;
this._length++;
return node;
}
add(19990);
//var ch1=add(1001);
console.log("ch",node1)