<h3>
Assignment 10, Creating a linked list and it's Hash Values
</h3>
<h4>
Programmed by Daniel Eberhart
</h4>
<h5>
website used for reference:
http://erlycoder.com/49/javascript-hash-functions-to-convert-string-into-integer-hash-
Djb2
</h5>
<div id="1"></div>
</br>
<div id="2"></div>
</br>
<div id="3"></div>
<div id="4"></div>
JavaScript
function Node(content, contentB){
this.content = content;
this.contentB = contentB;
this.next = null;
this.previous = null;
}
function IndexNode(source, element) {
this.source = source;
this.content = element;
}
function List(){
this._length = 0;
this._head = null;
this._tail = null;
}
List.prototype.pushFront = function(content, contentB){
var node = new Node(content, contentB, source);
if (this._length == 0) {
this._head = node;
this._tail = node;
} else {
this._tail.next = node;
node.previous = this._tail;
this._tail = node;
}
this._length++;
return node;
};
List.prototype.hash = function(key) {
key += store.toString().charCodeAt(store[i+1]);
var hash = key;
hash = ((hash <<5) - hash) + key;
if (hash < 0 ) {
hash = 10 + hash;
}
hash = hash & hash;
return hash;
};
List.prototype.print = function() {
var string = ' ';
var current = this._head;
while (current) {
string += current.content + ",";
current = current.next;
}
return string;
}
var list = new List();
var store = [];
var key = 0;
var count = 0;
var obj = new IndexNode(source);
for (var i = 0; i<10; i++){ //loop to create nodes
store[i] = Math.floor(Math.random()*1000);
count++;
var source = "Position"+count;
var element = list.hash(store[i]);
list.pushFront(store[i], element);// Content A has random values, B has the Hash values
obj[source] = element;//Once you have filled in all the ContentA and ContentB values you will create an object (similar to a Node) that contains (1) ContentB - the hashed value and (2) A pointer to the node it came from for each of the 10 nodes in the list.
store[i] = element + ">" + source;
//Sort the array lowest to highest
store.sort();
}
document.getElementById("2").innerHTML = "This list includes the hashed values from the randomly selected numbers:" +...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.