Assignment 8

by wooozy

HTML

<h1>Assignment 8</h1>
<p>Current Listing: <input type="button" value="Populate" onClick="populateList();" />
<br>
List Sort: <input type="button" value="Sort List" onClick="sortedListing();" />
<br>
ENTER: <input type="textbox" id="showValues" value="14" style="width: 25px;"/>
<input type="button" value="Insert Here" onClick="enterList();" />

<p id='showInfo'></p>

JavaScript

var Node = function(_content) {
  this.before = null;
  this.after = 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.before = this.front;
    this.front.after = 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.after = this.back;
    this.back.before = addedNode;
    this.back = addedNode;
    return this;
  }
  this.insertAfter = function(addedValues) {
    var listX = "";
    var node = this.back;
    if(addedValues < this.front.content){
      return "goesInFront";
    }
    if(addedValues > this.back.content){
      return  "goesInBack";
    }
    while (node != null) {
      if(addedValues > node.content){
        var newNode = new Node(addedValues);
        node.before.after = newNode;
        newNode.after = node;
        newNode.before = node.before;
        node.before = newNode;
        return "Inserted";
      }
      node = node.after;
    }
    return;
  }
  this.removeFront = function() {
    if (this.front == null) {
      return null;
    }
    var deletedContent = this.front.content;

    if(this.back == this.front){
      this.front = null;
      this.back = null;
      return deletedContent;
    }
    else{
      this.front = this.front.before;
      this.front.after = null;  
      return deletedContent;
    }
  }
  this.eraseBack = function() {
    if (this.front == null) {
      return null;
    }
    var deletedContent = this.back.content;
    if(this.back == this.front){
      this.front = null;
      this.back = null;
      return a;
    }
   ...