honoi
tower
by chris richarde
HTML
Choose quantity to sieve through for primes<br/>
<input type="textbox" id="value" />
<input type="button" id="stack" value="sieve" onClick="Math();" />
<p id="output"></p><br/>
JavaScript
var Node = function(content) {
this.next = null;
this.last = null;
this.content = content;
}
var Queue = function() {
this.bottom = null;
this.top = null;
this.length=0;
this.push = function(content){
if (this.bottom == null) {
this.bottom = new Node(content);
this.top = this.bottom;
this.length++;
return this;
}
var addedNode = new Node(content);
addedNode.last = this.top;
this.top.next = addedNode;
this.top = addedNode;
this.length++;
return this;
}
this.enqueue = function(content) {
if (this.bottom == null) {
this.top = new Node(content);
this.bottom = this.top;
this.length++;
return this;
}
var addedNode = new Node(content);
addedNode.next = this.bottom;
this.bottom.last = addedNode;
this.bottom = addedNode;
this.length++;
return this;
}
this.dequeue = function() {
if (this.bottom == null) {
alert("empty queue");
return null;
}
if (this.bottom == this.top) {
var a = this.bottom.content;
this.bottom=null;
this.next=null;
this.last=null;
this.length=0;
return a;
}
// Now remove top Node
var a = this.top.content; // hold value for return
this.top = this.top.last;
this.top.next = null;
this.length--;
return a;
}
this.toString = function() {
var str = "";
var node = this.bottom;
while (node != null) {
str += node.content + ":";
node = node.next;
}
return str;
}
}
function ClearDisplay(){
document.getElementById("output").innerHTML="";
}
function Print()
{
document.getElementById("output").innerHTML=Q1.toString();
}
function Math()
{
var i = 1;
var Q1 = new Queue();
var Q2 = new Queue();
var Q3 = new...