Skip to content

Instantly share code, notes, and snippets.

@cmstead
Created September 20, 2015 19:36
Show Gist options
  • Save cmstead/97de395eacc0c18c8395 to your computer and use it in GitHub Desktop.
Save cmstead/97de395eacc0c18c8395 to your computer and use it in GitHub Desktop.
A linked list factory in Javascript
var listItemFactory = (function(){
'use strict';
function ListItem(value){
this.value = value;
this.nextPointer = null;
}
ListItem.prototype = {
val: function(){
return this.value;
},
append: function(node){
var pointer = this.nextPointer;
this.nextPointer = node;
node.setNext(pointer);
},
setNext: function(pointer){
this.nextPointer = pointer;
},
next: function(){
return this.nextPointer;
}
}
function buildListItem(value){
return new ListItem(value);
}
return {
build: buildListItem
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment