File tree Expand file tree Collapse file tree 1 file changed +49
-1
lines changed
group03/619224754/src/com/coding/basic Expand file tree Collapse file tree 1 file changed +49
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .coding .basic ;
2
2
3
+ import java .util .Comparator ;
4
+
3
5
public class BinaryTreeNode {
4
6
5
7
private Object data ;
@@ -9,24 +11,70 @@ public class BinaryTreeNode {
9
11
public Object getData () {
10
12
return data ;
11
13
}
14
+
12
15
public void setData (Object data ) {
13
16
this .data = data ;
14
17
}
18
+
15
19
public BinaryTreeNode getLeft () {
16
20
return left ;
17
21
}
22
+
18
23
public void setLeft (BinaryTreeNode left ) {
19
24
this .left = left ;
20
25
}
26
+
21
27
public BinaryTreeNode getRight () {
22
28
return right ;
23
29
}
30
+
24
31
public void setRight (BinaryTreeNode right ) {
25
32
this .right = right ;
26
33
}
27
34
28
35
public BinaryTreeNode insert (Object o ){
29
- return null ;
36
+ BinaryTreeNode treeNode = new BinaryTreeNode ();
37
+ treeNode .data = o ;
38
+ int intO = Integer .parseInt (o .toString ());
39
+ int intData = Integer .parseInt (this .data .toString ());
40
+ if (intO > intData ){
41
+ if (this .right == null ){
42
+ this .right = treeNode ;
43
+ }
44
+ else {
45
+ this .right .insert (o );
46
+ }
47
+ }
48
+ else {
49
+ if (this .left == null ) {
50
+ this .left = treeNode ;
51
+ }
52
+ else {
53
+ this .left .insert (o );
54
+ }
55
+ }
56
+ return treeNode ;
57
+ }
58
+
59
+ private class MyComparator implements Comparator <BinaryTreeNode > {
60
+
61
+ @ Override
62
+ public int compare (BinaryTreeNode arg0 , BinaryTreeNode arg1 ) {
63
+ // TODO Auto-generated method stub
64
+ int int0 = Integer .parseInt (arg0 .data .toString ());
65
+ int int1 = Integer .parseInt (arg1 .data .toString ());
66
+ if (int0 > int1 ) {
67
+ return 1 ;
68
+ }
69
+ else if (int0 < int1 ){
70
+ return -1 ;
71
+ }
72
+
73
+ return 0 ;
74
+
75
+ }
76
+
77
+
30
78
}
31
79
32
80
}
You can’t perform that action at this time.
0 commit comments