-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeNode.java
63 lines (52 loc) · 1.43 KB
/
TreeNode.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* @author Skully (https://github.com/ImSkully)
* @email [email protected]
*/
public class TreeNode {
private Object item;
private TreeNode parentNode;
private TreeNode leftChild;
private TreeNode rightChild;
// Constructor.
public TreeNode(Object newItem) {
// Initializes tree node with item and no children.
item = newItem;
parentNode = null;
leftChild = null;
rightChild = null;
}
// Constructor with parent and children.
public TreeNode(Object newItem, TreeNode left, TreeNode right, TreeNode parent) {
// Initializes tree node with item and the left and right children references.
item = newItem;
parentNode = parent;
leftChild = left;
rightChild = right;
}
// Getters.
public Object getItem() {
return item;
}
public TreeNode getParent() {
return this.parentNode;
}
public TreeNode getLeft() {
return leftChild;
}
public TreeNode getRight() {
return rightChild;
}
// Setters.
public void setItem(Object newItem) {
item = newItem;
}
public void setParent(TreeNode parent) {
this.parentNode = parent;
}
public void setLeft(TreeNode left) {
leftChild = left;
}
public void setRight(TreeNode right) {
rightChild = right;
}
}