JSFiddle - React, Tailwind, and code Playground
by wooozy
HTML
<h1>
Assignment 7
</h1>
Nth Value: <input type="textbox" id="NthValue" value="7" size="1"/>
<br/><input type="button" value="Calculate" onClick="callRecursive();" />
<p id='Calculations'></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;
this.push = function(_content) {
if (this.front == null) {
this.front = new Node(_content);
this.back = this.front;
return this;
}
var addedNode = new Node(_content);
addedNode.previous = this.back;
this.back.next = addedNode;
this.back = addedNode;
return this;
}
this.removeFront = function() {
if (this.front == null) {
return null;
}
var contentRemoved = this.front.content;
if(this.back == this.front){
this.front = null;
this.back = null;
return contentRemoved;
}else{
this.front = this.front.next;
this.front.previous = null;
return contentRemoved;
}
}
this.removeBack = function() {
if (this.front == null) {
return null;
}
var contentRemoved = this.back.content;
if(this.back == this.front){
this.front = null;
this.back = null;
return contentRemoved;
}else{
this.back = this.back.previous;
this.back.next = null;
return contentRemoved;
}
}
this.toString = function() {
var str = "";
var node = this.front;
if (this.front == null){
str = "_empty_";
}else{
}
while (node != null) {
str += node.content + " ";
node = node.next;
}
return str;
}
this.countElements = function() {
var countX = 0;
var node = this.front;
while (node != null) {
node = node.next;
countX= countX+1;
}
return countX;
}
...