<html>
<head>
Juan Alban Franco
</head>
insert number to add
<input type = textbox id = "in">
<input type = button id = "add" value = "add to list" onclick = "add()">
<input type = button id = pr value = "Print LIst" onclick = "pr()">
<br>
<input type = button id = "test" value = "Generate List" onclick = "test()">
<br>
<input type = button id = "clear" value = "Clear List" onclick = "clr()">
<input type = button id = "bbl" value = "Bubble Sort" onclick = "bblsort()">
<input type = button id = "merge" value = "Merge Sort" onclick = "mergesort()">
<p id = array>
</p>
<p id = "out">
</p>
</html>
JavaScript
function linkedlist()
{
this.head = null;
this.tail = null;
this.length = 0;
}
function Node() {
this.content = 0;
this.next = null;
this.prev = null;
}
linkedlist.prototype.insert = function (_content) {
node = new Node();node.content = _content;
if(this.length < 1)
{
this.head = node;
this.tail = node;
this.length ++;
}
else{
this.tail.next = node;
node.prev = this.tail;
this.tail = node;
this.length ++;
}
}
linkedlist.prototype.print = function() {
var traveler = new Node();
traveler = this.head;
var string = "";
while (traveler)
{
string += traveler.content + " <br>";
traveler = traveler.next;
}
document.getElementById("out").innerHTML = string + this.length
}
linkedlist.prototype.clear = function () {
if(this.head != null){
this.head = null;
this.tail = null;
this.length = null;
document.getElementById("out").innerHTML = "";
}
else {return}
}
linkedlist.prototype.bubblesort = function(){
var traveler = this.head;
var length = this.length;
var holder_value = 0;
var i = 0;
var j = 0;
var counter = 0;
var last_step = null;
if (traveler == null){return;}
do{
counter = 0;
traveler = this.head;
while(traveler.next != last_step){
if(traveler.content > traveler.next.content){
counter ++;
holder_value = traveler.content;
traveler.content = traveler.next.content;
traveler.next.content = holder_value;
}
traveler = traveler.next;
}
last_step = traveler;
}
while (counter)
}
linkedlist.prototype.mergesort = function (head)
{
if(head == null || head.next == null){
return head;
}
var middle = this.middle(head);
head = this.mergesort(traveler);
middle = this.mergesort(middle);
alert(middle.content);
return this.merge(traveler,middle);
}
linkedlist.prototype.merge = function (first, second){
if (first == null) { return second;}
if (second == null) { return first;}
...
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.