-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.js
More file actions
36 lines (31 loc) · 791 Bytes
/
Node.js
File metadata and controls
36 lines (31 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// node class used to create new nodes for a linked list
class Node {
constructor(data) {
this.data = data;
this.next = null;
this.previous = null;
}
// points the current node to a specifeid next node
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')
}
}
// points a specified previous node to the current node
setPreviousNode(node) {
if (node instanceof Node || node === null) {
this.previous = node;
} else {
throw new Error('Previous node must be a member of the Node class')
}
}
getNextNode() {
return this.next;
}
getPreviousNode() {
return this.previous;
}
}
module.exports = Node;