-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeNode.java
More file actions
63 lines (55 loc) · 1.14 KB
/
Copy pathTreeNode.java
File metadata and controls
63 lines (55 loc) · 1.14 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package tree;
/**
* offerStructs.TreeNode 普通树节点
*/
public class TreeNode<T> {
T value;
TreeNode<T> leftChild;
TreeNode<T> rightChild;
TreeNode(T value){
this.value = value;
}
TreeNode(){
}
/**
* 增加左节点
* addLeft;
* @param value;
* void
*/
public void addLeft(T value){
TreeNode<T> leftChild = new TreeNode<>(value);
this.leftChild = leftChild;
}
/**
* 增加右节点
* addRight;
* @param value;
* void
*/
public void addRight(T value){
TreeNode<T> rightChild = new TreeNode<>(value);
this.rightChild = rightChild;
}
/**
* 重载hashCode
* @return int
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return this.value.hashCode();
}
/**
* @see java.lang.Object#equals(Object)
* @param obj
* @return
*/
@Override
public boolean equals(Object obj) {
if(!(obj instanceof TreeNode)){
return false;
}
return this.value.equals((TreeNode<?>)((TreeNode) obj).value);
}
}