Created
September 20, 2015 19:36
-
-
Save cmstead/97de395eacc0c18c8395 to your computer and use it in GitHub Desktop.
A linked list factory in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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