//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 =...
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.