Assignment 6

Daniel Eberhart

by Daniel Eberhart

HTML

Sieve of Eratosthenes

<br/>
Value of N: <input type="textbox" id="valueOfN" value="30" size="3"/>
<input type="button" value="Seed Queue L1" onClick="seedQueue();" />

<br/>
<input type="button" value="Run Iteration of Sieve" onClick="filterQueue();" />

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

JavaScript

var valueToProcess = '';
  var iteration = 0;
  var Node = function(_content) {
      this.next = null;
      this.previous = null;
      this.content = _content;

    }

  var Queue = function() {
    this.front = null;
    this.back = null;
    
// now push adds to the back
    this.push = function(_content) {
      // No front - create one
      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.removeFront = function() {
      if (this.front == null) {
        // alert("The Queue is Empty");
        return null;
      }
			var contentRemoved = this.front.content;

      if(this.back == this.front){
       
				    this.front = null;
    				this.back = null;
           	return contentRemoved;
      }else{
       this.front = this.front.next;
       this.front.previous = null;  
       return contentRemoved;
      }
    }




    this.removeBack = function() {
      if (this.front == null) {
        
        return null;
      }
			var contentRemoved = this.back.content;
      if(this.back == this.front){
        
				    this.front = null;
    				this.back = null;
           	return a;
      }else{
        this.back = this.back.previous;
        this.back.next = null;      
      	return contentRemoved;
      }
    }


    this.toString = function() {
      var str = "";
      var node = this.front;
      if (this.front == null){
        str = "Queue is Empty";
      }else{
        
      }
      while (node != null) {
        str += node.content + "&nbsp";
        node = node.next;
      }
      return str;
    }
    

    this.countElements = function() {
      var countX = 0;
      var node = this.front;
      while (node != null) {
        node = node.next;
   ...