/
Node.jack
45 lines (38 loc) · 870 Bytes
/
Node.jack
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
37
38
39
40
41
42
43
44
45
// Copyright (c) 2018, Bill Mei
// One node of a doubly-linked list.
class Node {
field int value;
field Node prev, next;
constructor Node new(int _value) {
let value = _value;
let prev = null;
let next = null;
return this;
}
// Get pointer to next node (if any)
method Node getNext() {
return next;
}
// Get pointer to previous node (if any)
method Node getPrev() {
return prev;
}
// Get the value of the node
method int getValue() {
return value;
}
// Set the next pointer to the provided node
method void setNext(Node node) {
let next = node;
return;
}
// Set the prev pointer to the provided node
method void setPrev(Node node) {
let prev = node;
return;
}
method void dispose() {
do Memory.deAlloc(this);
return;
}
}