-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeNode.java
More file actions
43 lines (37 loc) · 1.06 KB
/
TreeNode.java
File metadata and controls
43 lines (37 loc) · 1.06 KB
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
public abstract class TreeNode {
//fields
TreeNode leftChild;
TreeNode rightChild;
/** default constructor
*/
public TreeNode(){
leftChild = null;
rightChild = null;
}
/** constructor that receives also left and right children
* @param left The left child of the node
* @param right The right child of the node
*/
public TreeNode(TreeNode left, TreeNode right){
this.leftChild = left;
this.rightChild = right;
}
/** returns the left child of the node
* @return The TreeNode left child of the node.
*/
public TreeNode getLeft(){
return this.leftChild;
}
/** returns the right child of the node
* @return The TreeNode right child of the node.
*/
public TreeNode getRight(){
return this.rightChild;
}
/** returns if this node is a leaf or not
* @return true or false.
*/
public boolean isLeaf(){
return (this.leftChild == null) && (this.rightChild == null);
}
}