Javascript Linked List


This is a simple Javascript LinkedList class that I built for a work project. Once you see the structure of the print() function, you should be able to add other functions such as find() or delete() very easily.

// Class LinkedList, by Michael Grimm, http://mgrimm.net
function LinkedList() {
this._root = null;
}
LinkedList.prototype = {
// ADD()
add: function(node) {
var curr = this._root;
if (curr == null) {
this._root = node;
} else {
while (curr.next != null) {
curr = curr.next;
}
curr.next = node;
}
},
// PRINT()
print: function(currPage, currFolder) {
var curr = this._root;
while (curr != null) {
// Put code to print here
curr = curr.next;
}
}
};

  1. No comments yet.
(will not be published)
  1. No trackbacks yet.