Number of disks: <input type="textbox" id="valueOfN" value="2" size="3"/>
<br/>
<input type="button" value="Run Recursive Solution" onClick="callSolution();" />
<p id='reportOut'></p>
JavaScript
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;
// now push adds to the back
this.push = function(_content) {
// No front - create one
if (this.front == null) {
this.front = new Node(_content);
this.back = this.front;
return this;
}
// create a new node to be the back
var addedNode = new Node(_content);
// a) store pointer to current back
// as this.back of new node
addedNode.previous = this.back;
// b) store pointer to new back
// as this.back.next of current back
this.back.next = addedNode;
// c) store pointer to new back
// as this.back which becomes current back
this.back = addedNode; // which becomes new back
return this;
}
// the old 'pop' takes from the back
// this is not used in FIFO but let's not delete it.
// it can be used as a way to 'undo' a bad entry
// this is pop modified to take from the front
this.removeFront = function() {
if (this.front == null) {
// alert("The Queue is Empty");
return null;
}
var contentRemoved = this.front.content;
if(this.back == this.front){
// alert("The Queue Only Has one item");
this.front = null;
this.back = null;
return contentRemoved;
}else{
this.front = this.front.next;
this.front.previous = null;
return contentRemoved;
}
}
// pop now called removeBack
this.removeBack = function() {
if (this.front == null) {
// alert("The Queue is Empty");
return null;
}
var contentRemoved = this.back.content;
if(this.back == this.front){
// alert("The Queue Only Has one item");
this.front = null;
...
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.