Linked Lists
by Jeff Santos
HTML
<input type="button" value="Develop List" onclick="makeList()" />
<br/>
<br/>
<input type="button" value="Add to List" onclick="addNode" />
<input type="textbox" id="aNode" />
<p id="outcome"></p>
JavaScript
var list = null;
var screenOut = "";
function makeList() {
var value = document.getElementById("aNode").value;
list = new doublyList(value);
document.getElementById("outcome").innerHTML = list.print();
}
function doublyList(_content) {
this.length = 5;
this.head = nodeA;
this.tail = nodeE;
}
function addNode() {
var nnode = new Node(value);
value = document.getElementById("aNode").value;
list.addNode(value);
document.getElementById("outcome").innerHTML = list.print();
if (this.tail) {
this.tail.next = nNode
}
this.tail = nNode;
}
function nodeA() {
this.next = nodeB;
this.last = null;
this.value = "A";
return this;
}
function nodeB() {
this.next = nodeC;
this.last = nodeA;
this.value = "B"
return this;
}
function nodeC() {
this.next = nodeD;
this.last = nodeB;
this.value = "C"
return this;
}
function nodeD() {
this.next = nodeE;
this.last = nodeC;
this.value = "D";
return this;
}
function nodeE() {
this.next = null;
this.last = nodeD;
this.value = "E";
return this;
}
list.print = function(){
var screenOut = "";
var Head = this.head;
if(Head!= null){
screenOut = screenOut + Head.next ;
}
}