Assigment 7
Tower of Hanoi Recursion
by Jeremy Boss
HTML
Number of Disks (N)
<input type="textbox" id="disks" value="3" size="3" />
<br/>
<input type="button" value="Execute Tower Of Hanoi" onClick="solve();" />
<p id='printOut'></p>
JavaScript
/*
1.Big-O 2^n - 1
2. Given that each move would take 1s and 64 disks take 18,446,744,073,709,600,000 moves it would take 584,942,417,355.0736084 years in summation I would say yes we should be concerned
*/
//Globals
var TowerA;
var TowerB;
var TowerC;
var moves = 0;
var progStr = '';
var view = '';
var it = 0;
var valIn = '';
var iNode = function(_content) {
this.next = null;
this.previous = null;
this.content = _content;
}
var Queue = function() {
this.front = null;
this.back = null;
this.push = function(_content) {
if (this.front == null) {
this.front = new iNode(_content);
this.back = this.front;
return this;
}
var aNode = new iNode(_content);
aNode.previous = this.back;
this.back.next = aNode;
this.back = aNode;
return this;
}
this.removeFront = function() {
if (this.front == null) {
return null;
}
var amend = this.front.content;
if (this.back == this.front) {
this.front = null;
this.back = null;
return amend;
} else {
this.front = this.front.next;
this.front.previous = null;
return amend;
}
}
this.removeBack = function() {
if (this.front == null) {
return null;
}
var amend = this.back.content;
if (this.back == this.front) {
this.front = null;
this.back = null;
return amend;
} else {
this.back = this.back.previous;
this.back.next = null;
return amend;
}
}
this.toString = function() {
var string = "";
var node = this.front;
if (this.front == null) {
string = "No Disk";
} else {
}
while (node != null) {
string += node.content + " ";
node = node.next;
}
return string;
}
this.countElements = function() {
var count = 0;
var node = this.front;
while (node != null) {
node = node.next;
count = count + 1;
}
return count;
}
}
function recSol(x, from, to,...