Assignment 8

by Taylor Zimmerman

HTML

<html>
<body>
<h5>
First, create a list by clicking on 'Create List' button.
</h5>
<input type="button" value="Create List" onclick="CreateList()">
<h5>
Once list is created first sort the list with the 'Quick Sort' button. Next add your own values using the textbox and clicking 'Apply' to input into the list. Finally, sort your list with added values with the 'Merge Sort'.
</h5>
<input type="button" onclick="quickSort()" value=" Quick Sort"><br><br>
<input type="textbox" id="tbInput">
<input type="button" onclick="Insert()" value="Apply"><br><br>
<input type="button" onclick="mergeSort()" value="Merge Sort">

<div id="output">

</div>
</body>
</html>

JavaScript

var List = new LinkedList();
var d = "";

function Node(){
	this.content = null;
	this.next = null;
	this.last = null;
	return this;
}

function LinkedList(){
	this.head = null;
  this.tail = null;
  this.length = 0;
 
}

LinkedList.prototype.add = function(pass){
	var node = new Node();
  node.content = pass;
  
  if (this.head === null) {
    this.head = node;
    this.length = 1;
    return node;
  }

  if (this.tail == null) {
    this.tail = node;
    this.tail.last = this.head;
    this.head.next = this.tail;
    this.length = 2;
    return node;
  }

  this.tail.next = node;
  node.prev = this.tail;
  this.tail = node;
  this.length++;
  return node;
}

LinkedList.prototype.print = function(){
	if (this.head == null) return "Empty List";
	var node = this.head; 
  	while(node != null){
  	d +="<div>Node Value: " + node.content + "</div> ";
  node = node.next;
  }
  return d;
}

function CreateList(content){
  for (var i = 0; i < 20; i++){
    content = String.fromCharCode(65 + i);
    List.add(content);
    document.getElementById('output').innerHTML = List.print();
	}
}
function AddNode(){
	var addNode = document.getElementById("tbInput").value;
  List.add(addNode);
  document.getElementById('output').innerHTML = List.print();
}