Assignment 9 - Hashing
by aren_anderson
HTML
<h1>
Hashing
</h1>
<h4>
Please enter a value to hash: <input type="textbox" id="tbPhrase" />
</h4>
<input type="button" id="btnParse" value="Parse Phrase" onClick="parsePhrase();"/>
<div id="output">
</div>
JavaScript
//global variables for hashtable and LL
var hashTable = new HashTable();
var list = new LinkedList();
function LinkedList() {
this.length = 0;
this.head = null;
this.length = null
}
function Node(){
this.next = null;
this.prev= null;
this.content = null;
}
//function to add content to Node
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++;
return node;
}
this.tail.next = node;
node.prev = this.tail;
this.tail = node;
this.length++;
return node;
}
//function to parse text into hashTable
function parsePhrase(){
var phrase = 0;
phrase = document.getElementById("tbPhrase").value;
var phraseAsStringArray = phrase.split(" ");
var len = phraseAsStringArray.length;
for (var i = 0; i < len; i++){
hashTable.addWord(phraseAsStringArray[i]);
}
}