Assignment 7

by austinmillett

HTML

Value of N: <input type = "textbox" id = "valueOfN" size = "3" />

<br><br/>


<input type = "button" id = "Button" value = "Run Recursive Solution" onClick = "callSolution();" />

<br><br/>

<div id = 'reportOut'> </div>

CSS

/* Design for "Enter Number" button */
#Button {
background-color: black; 
border: 2px solid; 
color: white;
padding: 4px 8px; 
text-align: center; 
font-size: 15px; 
}

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;
}
      
//   create a new node to be the back
var addedNode = new Node(_content);

//   a) store pointer to current back
//      as this.back of new node
addedNode.previous = this.back;

//   b) store pointer to new back
//     as this.back.next of current back
this.back.next = addedNode;

//   c) store pointer to new back
//     as this.back which becomes current back
this.back = addedNode;        // which becomes new back
return this;
}

// the old 'pop' takes from the back
// this is not used in FIFO but let's not delete it.
// it can be used as a way to 'undo' a bad entry

// this is pop modified to take from the front
this.removeFront = function() {
if (this.front == null) {
// alert("The Queue is Empty");
return null;
}
var contentRemoved = this.front.content;

if(this.back == this.front){
// alert("The Queue Only Has one item");
this.front = null;
this.back = null;
return contentRemoved;
}else{
this.front = this.front.next;
this.front.previous = null;  
return contentRemoved;
}
}

// pop now called removeBack
this.removeBack = function() {
if (this.front == null) {
// alert("The Queue is Empty");
return null;
}
var contentRemoved = this.back.content;
if(this.back == this.front){
// alert("The Queue Only Has one item")
this.front = null;
this.back = null;
// fixed was 'a' nos is 'contentRemoved'
return contentRemoved;
}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 = "empty";
}else{
//str = "Queue: ";
}
while (node != null)...