<h1>
First create a randomized string list! Go ahead and push the button!
</h1>
<input type="button" value="Create Randomized String List" onClick="createRandomizedStringList();">
<br/>
<h2>
Sort the list you just created!
</h2>
<input type="button" value="Sort List" onClick="sortListResults();" />
<br/>
<h3>
Insert the value into the string!
</h3>
Insert Value: <input type="textbox" id="insertValue" value="" size="3"/>
<input type="button" value="Insert Value" onClick="insertSort();">
<p id='output1'></p>
<p id='output2'></p>
<p id='output'></p>
JavaScript
var Node = function(content) {
this.next = null;
this.previous = null;
this.content = content;
}
var Queue = function() {
this.front = null;
this.back = null;
//call variables
this.addToFront = function(content) {
if (this.front == null) {
this.front = new Node(content);
this.back = this.front;
return this;
}
//add variables to front
var addedNode = new Node(content);
addedNode.next = this.front;
this.front.previous = addedNode;
this.front = addedNode;
return this;
}
//adding nodes
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;
//insert function value to add to the list
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";
}
//insert the nodes when the "insert value" button is pressed.
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 is a back process
this.removeBack = function()...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.