<div id="wrapper">
<h2><div id="t">Assignment 7</div></h2>
<p id="t">TOH - Enter the number of blocks.. over 2</p>
<input type="text" id="tb1" onkeypress="handle(event)">
<input type="button" id="bt1" value="Button to press" onclick="submit()">
<div id="check"></div>
<div id="nom"><br></div>
<div id="error"></div>
<div id="t">1. What is the Complexity (In Big O)? </div>
<div id="show"></div>
<div id="t">2. Should we be concerned with concerned with the legend of the world ending when the 64 disk solution is physically solved it it takes 2 seconds for each move?</div>
<div id="show2"></div>
<div id="blocks"></div>
<div id="init"></div>
</div>
function handle(e) {
var key = e.keyCode || e.which;
if (key == 13) {
submit();
document.getElementById("tb1").value = "";
}
}
var x = 0;
var s1t, s2t, s3t = 0;
var Node = function(_content) {
this.next = null;
this.last = null;
this.content = _content;
}
var Stack = function() {
this.top = null;
this.bottom = null;
this.push = function(_content) {
if (this.bottom == null) {
this.bottom = new Node(_content);
this.top = this.bottom;
return this;
}
var addedNode = new Node(_content);
addedNode.last = this.top;
this.top.next = addedNode;
this.top = addedNode;
return this;
}
this.pop = function() {
if (this.top == null) {
return null;
}
if (this.bottom == this.top) {
this.bottom = null;
x = this.top.content;
return this.top.content;
}
var a = this.top.content;
this.top = this.top.last;
this.top.next = null;
x = a;
return a;
}
this.toString = function() {
var str = "";
var node = this.bottom;
while (node != null) {
str += " | " + node.content + " ";
node = node.next;
}
return str;
}
}
// the queues
var s1 = new Stack();
var s2 = new Stack();
var s3 = new Stack();
var counter = 0;
//Error handling function to display an error message
function diplay(check) {
//Initialize the message variable
var message = 'error';
document.getElementById("check").innerHTML = "";
}
function isInteger(number) {
return (number % 1 === 0);
}
//Recursive Tower of Hanoi function
//complete the tower
function solveHanoi(nod) {
//If the block number is greater than 0
if (nod > 0) {
//Call itself with one less than the block number
solveHanoi(nod - 1);
//Increase the counter
counter++;
//Call itself with one less than the block number
solveHanoi(nod - 1);
}
}
//Submit button...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.