Assignment 7 Tower of Hanoi

by austinmillett

HTML

<!-- Heading 1 -->
<h1> Austin Millett </h1>

<!-- Heading 2 -->
<h2> Assignment 7 - Recursion </h2>

<!-- Heading 3 -->
<h3>The Complexity in Big(O) is: O(2^n)</h3>

<h3>Second Question: We should not be concerned because it would take way to long years and years for the 64 disk solution to be physically solved. </h3>

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

<!-- Button for "Run" -->
<input type = "button" id = "Button" value = "Run" onClick = "getAnswer();" />

<br><br/>

<!-- Div for output -->
<div id = "Output"></div>

CSS

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

JavaScript

// Initialize global
var towerA;
var towerB;
var towerC;
var moves = 0;
var progressString = '';
var report  = '';

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;
    
// Push adds it to the back
this.push = function(_content) {
if (this.front == null) {
this.front = new Node(_content);
this.back = this.front;
return this;
}
      
//Creates a new node to be the last 
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) {
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;
}
}

//removeBack is now pop
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 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
{
}
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;
countX= countX+1;
}
return countX;
}
}

// Recursive function  
function recursiveSolution(x,towerFrom,towerTo,towerUtility) {
if (x > 1){
recursiveSolution(x-1,towerFrom,towerUtility,towerTo);
recursiveSolution(1,towerFrom,towerTo,"");
recursiveSolution(x-1,towerUtility,towerTo,towerFrom);
}
if (x == 1){
moveXtoY(towerFrom,towerTo);
}
}

// Move a Disk
function...