<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();
}
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.