Assignment 4

Double Linked List

by Nyle Anderson

HTML

<input type="button" id="newDoubleLinkedList" value="Create Randomized String List" onClick="newDoubleLinkedList();" />
<input type="button" id="swapSort" value="Insertion Sort" onClick="insertionSort();" />
<input type="button" id="bubbleSort" value="Bubble Sort" onClick="bubbleSort();" />
<input type="textbox" id="nodeName" Value="Enter String Here" />
<input type="button" id="insertString" value="Insert String" onClick="addNode();" />

<p id="output"></p>

JavaScript

//create the list
function newDoubleLinkedList() {
  var value = document.getElementById("nodeName").value;
  list = new List(value);
  //defining the list
  var list = new doubleLinkedList();
  var id =;
  id=0
  list = new doubleLinkedList(null, 0, null)
  list.add('1');
  list.add('2');
  list.add('3');
  list.add('4');
  list.add('5');
  document.getElementById("output").innerHTML = doubleLinkedList.print();
}
//add in a node
function addNode() {
  var value = document.getElementById("nodeName").value;
  list.addNode(value);
  document.getElementById("output").innerHTML = list.print();
}
//the link object
function node(id,content,next,last) {
	this.id=id;
  this.content=content;
  this.next=next;
  this.last=last;
  return this;
}

Node.prototype.asString = function() {
  return "The new node is:" + this.content + "<br/>";
}
//Define list object
function List(value) {
  this.length = 1;
  this.head = new Node(value, null); // Pointer TO the head is null
  this.last = this.head;  // When created - head and last are the same.
}

DoubleLinkedList.prototype.length = function() {
  var i = 0;
  var node = this.head;

  while (node != 0) {
    i++;
    node = node.next;
  }
  return i;
};

DoubleLinkedList.prototype.asString = function() {
  
  var str = 'Linked List with ' + this.length + ' nodes <br/>';
  var node = this.head;


  while (node != 0) {
    str +="Node ID:" + node.id +  ': Node Value: ' + node.content;

    str += "<br>";
    node = node.next;
  }
  return str;


function bubbleSort() {
  var n = list.length
  var passCount = 0
  var swap = 0
  var temp = ""
  var listA = list.head //How to point to the first and next nodes?
  for (passCount > 0, passCount == list.n - 1, passCount < 1){
  	for (swap > 0, swap == list.n - 1, swap < 1){
    	if(list.n > list.n + 1){
    		temp[swap] == listA[swap + 1];
        listA[swap] == listA[swap + 1];
        listA[swap + 1] == temp;
        }
   	 }
    }
}

function insertionSort() {
  var i = "";
  var j =...