Index_demo
by davidjb95
HTML
<p id='output'></p>
Sorted
<p id='output2'></p>
JavaScript
function addNode() {
var value = parseInt(document.getElementById("LinkName").value);
ll.add(value);
length++;
LinkedList.prototype.bubbleSort();
}
var LinkedList = function () {
var LinkedListNode = function (content) {
this.next = null;
this.content = content;
};
var LinkedListNode2 = function (hash, source) {
this.next = null;
this.content = hash;
this.source = source;
};
this.add = function (content) {
if (this.head == null) {
this.head = new LinkedListNode(content);
return this.head;
}
if (this.tail == null) {
this.tail = new LinkedListNode(content);
this.head.next = this.tail;
return this.tail;
};
this.tail.next = new LinkedListNode(content);
this.tail = this.tail.next;
this.tail.next = null;
return this.tail;
};
this.toHash = function(h) {
var hash = 0;
var source = h;
//http://burtleburtle.net/bob/hash/integer.html
hash = (source ^ 61) ^ (hash >> 16);
hash = hash + (hash << 3);
hash = hash ^ (hash >> 4);
hash = hash * 0x27d4eb2d;
hash = hash ^ (hash >> 15);
if (this.head == null) {
this.head = new LinkedListNode2(hash, source);
return this.head;
}
if (this.tail == null) {
this.tail = new LinkedListNode2(hash, source);
this.head.next = this.tail;
return this.tail;
};
this.tail.next = new LinkedListNode2(hash, source);
this.tail = this.tail.next;
this.tail.next = null;
return this.tail;
return hash;
};
}
LinkedList.prototype.toString = function () {
var i = 1;
var str = 'Linked List <br/>'
var node = this.head;
while (node != null) {
str += i + ': Node: ' + node.source + " -> " + node.content;
i++;
str += '<br/>';
node = node.next;
}
return...