JSFiddle - React, Tailwind, and code Playground
HTML
<h2>Module 07</h2>
<h3>Assignment 8</h3>
<p>New list: <input type="button" value="Populate" onClick="populateList();" />
<br>
Sort the list: <input type="button" value="Sorted Listing" onClick="sortedListing();" />
<br>
Insert into list: <input type="textbox" id="insertedValues" value="14" style="width: 25px;"/>
<input type="button" value="Insert" onClick="insertList();" />
<p id='theInfo'></p>
JavaScript
var Node = function(_content) {
this.next = null;
this.previous = null;
this.content = _content;
}
var Queue = function() {
this.front = null;
this.back = null;
this.addToFront = function(_content) {
if (this.front == null) {
this.front = new Node(_content);
this.back = this.front;
return this;
}
var addedNode = new Node(_content);
addedNode.next = this.front;
this.front.previous = addedNode;
this.front = addedNode;
return this;
}
this.addToBack = 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.insertAfter = function(valueToAdd) {
var listX = "";
var node = this.back;
if(valueToAdd < this.front.content){
return "goesInFront";
}
if(valueToAdd > this.back.content){
return "goesInBack";
}
while (node != null) {
if(valueToAdd > node.content){
var newNode = new Node(valueToAdd);
node.next.previous = newNode;
newNode.previous = node;
newNode.next = node.next;
node.next = newNode;
return "Inserted";
}
node = node.previous;
}
return;
}
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 a;
}
...