Created
February 19, 2024 01:30
-
-
Save tdubs42/8b1d0e49bc5e9a95e2325b46b411576e to your computer and use it in GitHub Desktop.
Node Class for Linked List - 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
class Node { | |
constructor(data) { | |
this.data = data; | |
this.next = null; | |
} | |
setNextNode(node) { | |
if (node instanceof Node || node === null) { | |
this.next = node; | |
} else { | |
throw new Error('Next node must be a member of the Node class') | |
} | |
} | |
getNextNode() { | |
return this.next; | |
} | |
} | |
module.exports = Node; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment