-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTreeNode.java
More file actions
51 lines (43 loc) · 901 Bytes
/
TreeNode.java
File metadata and controls
51 lines (43 loc) · 901 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.ub.interview;
public class TreeNode<E> implements Comparable<E> {
private E payLoad;
private TreeNode<E> left;
private TreeNode<E> right;
public TreeNode(E aPayLoad) {
payLoad = aPayLoad;
left = null;
right = null;
}
public TreeNode<E> getLeft() {
return left;
}
public TreeNode<E> getRight() {
return right;
}
public E getPayLoad() {
return payLoad;
}
@Override
public String toString() {
return (String)this.getPayLoad();
}
@Override
public int compareTo(E o) {
//If it is type of String
if(o instanceof String) {
return this.toString().compareTo((String) o);
}
//If it is type of Integer
else if(o instanceof Integer) {
if((Integer) o < (Integer)this.getPayLoad()) {
return 0;
}
else { // if greater or equal
return 1;
}
}
else {
return 0;
}
}
}