-
Notifications
You must be signed in to change notification settings - Fork 19.5k
/
SimpleTreeNode.java
90 lines (79 loc) · 2.4 KB
/
SimpleTreeNode.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.thealgorithms.devutils.nodes;
/**
* Simple TreeNode extension that holds references to two child Nodes (left and
* right).
*
* @param <E> The type of the data held in the Node.
*
* @author <a href="https://github.com/aitorfi">aitorfi</a>
*/
public class SimpleTreeNode<E> extends TreeNode<E> {
/**
* Refrence to the child Node on the left.
*/
private SimpleTreeNode<E> leftNode;
/**
* Refrence to the child Node on the right.
*/
private SimpleTreeNode<E> rightNode;
/**
* Empty contructor.
*/
public SimpleTreeNode() {
super();
}
/**
* Initializes the Nodes' data.
*
* @param data Value to which data will be initialized.
* @see TreeNode#TreeNode(Object)
*/
public SimpleTreeNode(E data) {
super(data);
}
/**
* Initializes the Nodes' data and parent node reference.
*
* @param data Value to which data will be initialized.
* @param parentNode Value to which the nodes' parent reference will be set.
* @see TreeNode#TreeNode(Object, Node)
*/
public SimpleTreeNode(E data, SimpleTreeNode<E> parentNode) {
super(data, parentNode);
}
/**
* Initializes the Nodes' data and parent and child nodes references.
*
* @param data Value to which data will be initialized.
* @param parentNode Value to which the nodes' parent reference will be set.
* @param leftNode Value to which the nodes' left child reference will be
* set.
* @param rightNode Value to which the nodes' right child reference will be
* set.
*/
public SimpleTreeNode(E data, SimpleTreeNode<E> parentNode, SimpleTreeNode<E> leftNode, SimpleTreeNode<E> rightNode) {
super(data, parentNode);
this.leftNode = leftNode;
this.rightNode = rightNode;
}
/**
* @return True if the node is a leaf node, otherwise false.
* @see TreeNode#isLeafNode()
*/
@Override
public boolean isLeafNode() {
return (leftNode == null && rightNode == null);
}
public SimpleTreeNode<E> getLeftNode() {
return leftNode;
}
public void setLeftNode(SimpleTreeNode<E> leftNode) {
this.leftNode = leftNode;
}
public SimpleTreeNode<E> getRightNode() {
return rightNode;
}
public void setRightNode(SimpleTreeNode<E> rightNode) {
this.rightNode = rightNode;
}
}