Assignment 8

by Kristy Bond

HTML

<input type="button" value="Repopulate Randomly (first) " onClick="repopulateRandomly();" /> Calls a random string of numbers
<br/>
<input type="button" value="Merge Sort (second)" onClick="CallMergeSort();" /> Puts string in order <br/> Value to add: <input type="textbox" id="valueToInsert" value="6" size="3" />
<input type="button" value="Insertion Sort (last) " onClick="CallInsertSort();" /> Puts new value in correct order.

<p id='output1'></p>
<p id='output2'></p>
<p id='reportOut'></p>

JavaScript

//   Assignment 8 
// automatically populate the List with 20 elements
// add two sort functions
// buttons to (1) Repopulate the list with Random strings , (2) Sort //list with selected algorithm 1 (3) Sort list with selected algorithm 2 and (4) Insert a new random string entered by the user into the list
// text box for user to insert new string. 




var Node = function(_content) {
  this.next = null;
  this.previous = null;
  this.content = _content;
}
var Queue = function() {
  this.front = null;
  this.back = null;




  this.addToFront = function(_content) {

    if (this.front == null) {
      this.front = new Node(_content);
      this.back = this.front;
      return this;
    }

    var addedNode = new Node(_content);

    addedNode.next = this.front;

    this.front.previous = addedNode;

    this.front = addedNode;
    return this;
  }


  this.addToBack = function(_content) {
    if (this.front == null) {
      this.front = new Node(_content);
      this.back = this.front;
      return this;
    }

    var addedNode = new Node(_content);

    addedNode.previous = this.back;
    this.back.next = addedNode;

    this.back = addedNode;
    return this;
  }


  this.insertAfter = function(valueToAdd) {
    var listX = "";
    var node = this.back;

    if (valueToAdd < this.front.content) {
      return "goesInFront";
    }
    if (valueToAdd > this.back.content) {
      return "goesInBack";
    }

    while (node != null) {
      if (valueToAdd > node.content) {

        var newNode = new Node(valueToAdd);

        node.next.previous = newNode;

        newNode.previous = node;

        newNode.next = node.next;

        node.next = newNode;
        return "inserted";
      }
      node = node.previous;
    }

    return;
  }



  this.removeFront = function() {
    if (this.front == null) {

      return null;
    }
    var contentRemoved = this.front.content;

    if (this.back == this.front) {

      this.front = null;
      this.back = null;
     ...