JSFiddle - React, Tailwind, and code Playground
by Ryan Brown
HTML
<form id="formski">
<input type="textbox" id="n_numb" value="6" />
<input type="button" id="btnClick" value="Insert # of Discs" onclick="" />
</form>
JavaScript
var Node = function(_content) {
this.next = null;
this.last = null;
this.content = _content;
}
var Stack = function() {
this.bottom = null;
this.top = 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; // pointer to previous node
this.top.next = addedNode; // current top points to new
this.top = addedNode; // which becomes new top
return this;
}
this.pop = function() {
if (this.bottom == null) {
alert("The Stack is Empty");
return null;
}
// Case of one node
if (this.bottom == this.top) {
var a = this.top.content;
this.bottom = null;
this.top = null;
return a;
}
// Now remove top Node
var a = this.top.content; // hold value for return
this.top = this.top.last;
this.top.next = null;
return a;
}
this.toString = function() {
var str = "";
var node = this.bottom;
while (node != null) {
str += node.content + ":";
node = node.next;
}
return str;
}
this.even = function() {
var y = parseInt(stack.pop());
if (Number.isNaN(z) == false) {
stack.push(z);
} else {
alert("Read the directions and try again.");
}
}
this.odd = function() {
var y = parseInt(stack.pop());
stackC.push(y);
var z = parseInt(stack.pop());
stackB.push(z);
else
}
}
var StackB = new Stack();
var StackC = new Stack();
function Calculate() {
var cal = document.getElementById("n_numb").value;
stack.push(cal);
if ((cal % 2) == 0)
// even
stack.pop;
stack.even;
else
// odd
stack.pop;
stack.odd;
}