Skip to content

Instantly share code, notes, and snippets.

@tdubs42
Created February 19, 2024 01:30
Show Gist options
  • Save tdubs42/8b1d0e49bc5e9a95e2325b46b411576e to your computer and use it in GitHub Desktop.
Save tdubs42/8b1d0e49bc5e9a95e2325b46b411576e to your computer and use it in GitHub Desktop.
Node Class for Linked List - JavaScript
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