assignment 4

by austinmillett

HTML

<input type="text" id="v" value="Node1" />
<input type="button" value="Add Node" onclick"addNode"/>
<div

JavaScript

function linkedList() {
this.head = null;
this.tail = null;
this.length = 0;
}

function Node1() {
this.next = null;
this.prev = null;
this.content = null;
}

linkedList.prototype.add = function(content) {
var node = new Node(); node.content = content;

if (this.head == null){
this.head = node; this.length = 1;
return node;
} 

if (this.tail == null) {
this.tail = node;
this.tail.prev = this.head;
this.head.next = this.tail;
this.length = 2;
return node;
}

this.tail.next = node;
node.prev = this.tail;
this.tail = node;
return node;

}

linkedList.prototype.print = function() {
if (this.head == null) return "Empty List";
var s = "";
var node = this.head;
while (node != null) {
s += node.content + "   ";
node = node.next;
}
return s;
}