queue

by Peyton Hessler

HTML

<form id="formski">
  <div>
    <H4> Enter a number that is greater than or equal to 2</H4>
    <input type="textbox" id="uEntry" value="10">
    <br>
    <input type="button" value="Enter the queue amount" id="uButton" onClick="iteration();">
    <p id="par1">
    </p>
    <p id="par2">
    </p>
  </div>
</form>

JavaScript

// With this program I am trying to code a basic queue and show how that queue works. With this queue I am showing the full list of numbers in the iteration 0, but then take away all the queue numbers divisble by two except two. Then the new queue numbers are shown on the iteration 1. Every iteration after that show how the numbers move from the enqueue to the dequeue.

var number = document.getElementById("uEntry").value;
var n1 = 0;
var n2 = 0;
var it = 0;

var Node = function(_content) // Create the properties for the node that will be manipulated later.
  {
    this.next = null;
    this.previous = null;
    this.content = _content;
  }

var uQueue = function() // Here I am going to create the queue.
  {
    this.last = null;
    this.first = null;
    this.length = 0;

    this.enqueue = function(_content) // Here I am creating the enqueue, which is the start of the queue. The function for the dequeue is the end of the queue. These two function use is to create nodes that point to each other.
      {
        var node = new Node(_content);
        if (this.last == null && this.head == null) {
          this.first = node;
          this.last = node;
          this.length++;
          return this;
        }
        this.last.previous = node;
        node.next = this.last;
        this.last = node;
        this.length++;
        return this;
      }
    this.dequeue = function() {
      if (this.last == this.first) {
        this.first = null;
        this.last = null;
        this.length = 0;
        return null;
      }
      var temp = this.first;
      this.first = this.first.previous;
      this.first.next = null;
      this.length--;
      return temp;
    }
    this.toString = function() {
      var call = " ";
      var node = this.first;
      while (node != null) {
        call += "  " + node.content + "  ";
        node = node.previous;
      }
      return call;
    }
  }

var FirstQueue = new uQueue();
var SecondQueue = new uQueue();

// Here i am...