Assignment 7 Tower

by pat spag

HTML

Tower of Hanoi Time Complexity O(2^n)
<br>
Enter number of disk's
<input type="textbox" id="numOfDisk" value="5" >
<br>
<input type="button" value="Submit" onclick="runHanoi()">
<input type="button" value="Clear Results" onclick="clearDisplay();">
<input type="button" value="64 Disk Legend" onclick="diskLegend()">
<div id="output">

</div>

JavaScript

var moveOutput="";
var towerFrom; var towerVia; var towerTo;
var moves = 0;
var node = function(val){
	this.next = null;
	this.previous = null;
	this.content = val;
	};
  // queue from last assignment
  var queue = function(){
	this.front = null;
  this.back = null;
  
  this.push = function(enQueueVal){
  //creating first node in que 
  	if (this.front == null){
    	this.front = new node(enQueueVal);
      this.back = this.front;
      return this;
    }else{
    	var addedNode = new node(enQueueVal);
   		addedNode.previous = this.back;
    	this.back.next = addedNode;
    	this.back = addedNode;
    	return this;
  	}
  };
  
  this.pop = function(){
  	if(this.front == null){
    	return null;
    }
    var poppedVal = this.back.content;
    	if(this.back == this.front){
      this.front = null;
      this.back = null;
      return poppedVal;
      }else{
      	this.back = this.back.previous;
        this.back.next = null;
        return poppedVal;
      }
  };
      this.toString = function(){
    var str ="";
    var node = this.front;
    if (this.front == null){
    	str = "  ";
      }else{
    }
    while (node != null) {
      str += node.content + "  ";
      node = node.next;
      }
      return str;  
      
    };//count for nodes
      this.count = function(){ 
      var count = 0;
      var counterNode = this.front;
      while (counterNode != null){
      	counterNode= counterNode.next;
      	count +=1
       }
      return count;      
    }  
};
function createMoveOutput(poppedTower, pushedTower){
	if (poppedTower == "FROM"){
    poppedDisk = towerFrom.pop();
      }
  if (poppedTower == "VIA"){
    poppedDisk = towerVia.pop();
    }
  if (poppedTower == "TO"){
    poppedDisk = towerTo.pop();
    }
  if (poppedTower == null) {
    	moveOutput += null;
    }else{
    if (pushedTower == "FROM"){
      towerFrom.push(poppedDisk);
    }
    if (pushedTower == "VIA"){
      towerVia.push(poppedDisk);
    }
    if (pushedTower == "TO"){
     ...