Assignment 10

Indexing -Corrected

by Jenni Meiklejohn

HTML

<h1><center> Assignment 10</center></h1>
<h2><center> Indexing </center></h2> Random List:
<br/>
<div id="output1"> </div>
<br/> Hash Output:
<br/>
<div id="output2"> </div>
<br/> Indexing:
<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;
      return;
    }


    var addedNode = new Node(ContentA, ContentB)
    addedNode.previous = this.top;
    this.top.next = addedNode;
    this.top = addedNode;
    return;

  }

  this.ContentAToString = function() {
    var str = "";
    var node = this.bottom;
    while (node != null) {
      str += node.ContentA + "<br>";
      node = node.next;
    }
    return str;
  }

  this.ContentBToString = function() {
    var str = "";
    var node = this.bottom;
    while (node != null) {
      str += "List Value: " + node.ContentA + " - " + " Hash Value: " + 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 Value:  " + 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";
 ...