JSFiddle - React, Tailwind, and code Playground

by Jeff Santos

HTML

<input type="button" value="Repopulate Randomized String List" onClick="repopulateRand();" />
<br/>
<input type="button" value="Merge Sort" onClick="mergeSort();" />

<br/> Value to Insert: <input type="textbox" id="insertV" value=""  />
<input type="button" value="Insertion Sort" onClick="insertSort();" />

<p id='output1'></p>
<p id='output2'></p>
<p id='output3'></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 "front";
     }
     if (valueToAdd > this.back.content) {
       return "back";
     }

     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 vRemoved = this.front.content;

     if (this.back == this.front) {

       this.front = null;
       this.back = null;
       return vRemoved;
     } else {
       this.front = this.front.next;
       this.front.previous = null;
       return vRemoved;
     }
   }


   this.removeBack = function() {
     if (this.front == null) {
       return null;
     }
     var vRemoved = this.back.content;
     if (this.back == this.front) {
      ...