JSFiddle - React, Tailwind, and code Playground
by Jenni Meiklejohn
HTML
<h1><center> Assignment 10</center></h1>
<h2><center> Indexing </center></h2> Random List:
<br/>
<div id="output1"> </div>
<br/> Output of Hash:
<br/>
<div id="output2"> </div>
<br/> Index:
<br/>
<div id="output3"> </div>
JavaScript
function Node(ContentA,ContentB){
this.indexer = null;
this.next = null;
this.previous = null;
this.ContentA = ContentA;
this.ContentB = ContentB;
}
function Stack(){
this.bottom = null;
this.top = null;
this.push = function(ContentA,ContentB){
if(this.bottom == null){
this.bottom = new Node(ContentA,ContentB);
this.top = this.bottom;
}
var addedNode = new Node(ContentA,ContentB)
addedNode.previous = this.top;
this.top.next = addedNode;
this.top = addedNode;
}
this.ContentAToString = function(){
var str = "";
var node = this.bottom;
while(node != null){
str += "Value: " + node.ContentA + "<br>";
node = node.next;
}
return str;
}
this.ContentBToString = function(){
var str = "";
var node = this.bottom;
while(node != null){
str += "Value: " + node.ContentA+ ", Hash: " + node.ContentB + "<br>";
node = node.next;
}
return str;
}
}
Stack.prototype.randomStack = function(){
var n = 10;
var node = this.bottom;
for(var i = 1; i <= n ; i++ ){
this.push(randomString());
document.getElementById("output1").innerHTML = this.ContentAToString();
}
}
Stack.prototype.hash = function(){
var node = this.bottom;
while(node != null){
node.ContentB = hashingFunction(node.ContentA);
node.indexer = node.ContentA;
node = node.next;
}
document.getElementById("output2").innerHTML
= this.ContentBToString();
}
Stack.prototype.createIndex = function(){
var node = this.bottom;
var i = 0;
while(node!=null){
index[i] = " Hash: " + node.ContentB + " --> " + node.indexer;
node = node.next;
i++;
}
}
print = function (arr){
for(var i = 0; i < arr.length; i++){
document.getElementById("output3").innerHTML += arr[i] + "<br/>";
}
}
function randomString(){
var s= "";
var charOptions = "abcdefghijklmnopqrstuvwxyz0123456789";
for(var i = 0; i < 5; i++){
s += charOptions.charAt(Math.floor(Math.random() *...