JSFiddle - React, Tailwind, and code Playground
by wooozy
HTML
<h2>Assignment 6</h2>
<p>Nth Value: <input type="textbox" id="nthvalue" value="40" style="width: 40px;" /><br>
<input type="button" value="Input Queue" onClick="InputQueue();" /><br/>
<input type="button" value="Test" onClick="TestSortedQ();" /></p>
<p id='releaseStatement'></p>
JavaScript
var theValue = '';
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 sepNode = new Node(_content);
sepNode.previous = this.back;
this.back.next = sepNode;
this.back = sepNode;
return this;
}
this.removeFront = function() {
if (this.front == null) {
return null;
}
var RemoveCont = this.front.content;
if(this.back == this.front){
this.front = null;
this.back = null;
return RemoveCont;
}else{
this.front = this.front.next;
this.front.previous = null;
return RemoveCont;
}
}
this.removeBack = function() {
if (this.front == null) {
return null;
}
var RemoveCont = this.back.content;
if(this.back == this.front){
this.front = null;
this.back = null;
return a;
}else{
this.back = this.back.previous;
this.back.next = null;
return RemoveCont;
}
}
this.toString = function() {
var str = "";
var node = this.front;
if (this.front == null){
str = " ";
}
while (node != null) {
str += node.content + " ";
node = node.next;
}
return str;
}
this.countElements = function() {
var count = 0;
var node = this.front;
while (node != null) {
node = node.next;
count= count+1;
}
return count;
}
}
function TestSortedQ() {
if (Set1.countElements() > 0) {
Set2 = new Queue();
var hold = Set1.removeFront();
theValue = hold;
SetOut.push(theValue);
while (hold != null) {
var x = hold % theValue;
if (x >= 1 ) {
...