JSFiddle - React, Tailwind, and code Playground
by wooozy
HTML
<!-- forked from Sample by Dr. Eaglin
https://jsfiddle.net/reaglin/0LLt6q55/ -->
<p id='endReport'></p>
JavaScript
var Node = function(_content) {
this.next = null;
this.last = null;
this.content = _content;
}
var Stack = function() {
this.head = null;
this.top = null;
this.push = function(_content) {
if (this.head == null) {
this.head = new Node(_content);
this.top = this.head;
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.head == null) {
return null;
}
var a = this.top.content;
if(this.top == this.head){
this.head = null;
this.top = null;
return a;
}else{
this.top = this.top.last;
this.top.next = null;
return a;
}
}
this.toString = function() {
var str = "";
var node = this.head;
if (this.head == null){
str = "Stack is Empty";
}else{
}
while (node != null) {
str += node.content + " ";
node = node.next;
}
return str;
}
this.countElements = function() {
var count = 0;
var node = this.head;
while (node != null) {
node = node.next;
count= count+1;
}
return count;
}
}
var runcalc = '<input type="textbox" id="operatorIn" value="+" size="1"/><input type="button" value="Run Calculator" onClick="runCalculator();" />';
var removeelement = '<input type="button" value="Remove Element" onClick="deleteElement();" />';
var AddStack = '<input type="textbox" id="newValue" value="10" size="3"/><input type="button" value="Add Stack" onClick="addToStack();" />';
function addToStack() {
var newValue = document.getElementById("newValue").value;
stackReport = "";
stackReport += "Added:" + newValue;
stack.push(newValue);
...