Sorting 22

by pat spag

HTML

<input type="button" value="Create Randomized String List" onclick="populateList();">
<br>
<input type="button" value="Merge Sort" onclick="callMergeSort()">
<br>
<input type="button" value="Bubble Sort" onclick="bubbleSort();">
<br>
<input type="text" value="9" id="textInput" size="8">
<input type="button" value="Insert String" onclick="InsertSort();">
<br> <br>
<div id="output">
</div>
<div id="output2">
</div>
<div id="output3">
</div>
<div id = "output4">

</div>
<div id = "output5">
</div>
<br>
<div id = "output5">
<div id = "output6">
</div>

JavaScript

var node = function(val){
this.next = null;
  this.previous=null;
  this.content = val;
};
var list = function(){
this.head = null;
  this.tail = null;
  this.length = 0;
  
  this.addTail = function(val){
  if (this.head == null){
  this.head = new node(val);
    this.tail = this.head;
    return this;
  }
  var addedNode = new node(val);
  addedNode.previous = this.tail;
  this.tail.next = addedNode;
  this.tail = addedNode;
  return this;
  }
  
  this.addHead = function(val){
  if (this.head == null){
    this.head= new node(val);
      this.tail = this.head;
      return this;
  }
    addedNode = new node(val);
    addedNode.next = this.head;
    this.head.previous = addedNode;
    this.head = addedNode;
    return this;
 	}
  this.discardTail = function(){
  if (this.head == null){
    return null;
    }
    var discardTailContent = this.tail.content;
    if(this.tail == this.head){
      this.head = null;
        this.tail = null;
        return discardTailContent;
      }else{
      this.tail = this.tail.previous;
        this.tail.next = null;
        return discardTailContent;
      }
  }
  this.discardHead = function (){
  if (this.head ==null){
    return null;
    }
    var discardHeadContent = this.head.content;
    if (this.head == this.tail){
      this.head = null;
        this.tail = null;
        return discardHeadContent;
      }else{
      this.head = this.head.next;
        this.head.previous = null;
        return discardHeadContent;
      }
  }
  
 	this.toString = function(){
  var str= "";
    var node = this.head;
    if (this.head == null){
    str = "Already Merge Sorted -- Generate New Random List to Bubble Sort"
    }
    
    while (node != null){/* https: *///jsfiddle.net/L6ykqzq3/31/#run
           str += node.content + " ";
           node = node.next;
         }
      return str;
  }
  this.count = function (){
  var count = 0;
  var counterNode = this.head;
  while (counterNode != null){
  counterNode = counterNode.next;
   ...