1
- package com .datastructures ;
1
+ package com .dataStructures ;
2
2
3
3
/**
4
4
* Binary tree for general value type, without redundancy
8
8
9
9
public class BinaryTree <T extends Comparable > {
10
10
private final T data ;
11
- private BinaryTree < T > right , // the upper binary tree
11
+ private BinaryTree right , // the upper binary tree
12
12
left ; // the lower binary tree
13
13
14
14
public BinaryTree (T data ) {
@@ -21,38 +21,35 @@ public String toString() {
21
21
}
22
22
23
23
/**
24
- * inserts a new value in it's correspondent place
24
+ * inserts a new value in it's correspondant place
25
25
*
26
26
* @param newDataValue value of the new binary tree to add on this tree
27
27
*/
28
28
public void insert (T newDataValue ) {
29
- this .insert (new BinaryTree <> (newDataValue ));
29
+ this .insert (new BinaryTree (newDataValue ));
30
30
}
31
31
32
32
/**
33
- * inserts a new binary tree in it's correspondent place
33
+ * inserts a new binary tree in it's correspondant place
34
34
*
35
35
* @param newData new value to add on this tree
36
36
*/
37
- public void insert (BinaryTree < T > newData ) {
37
+ public void insert (BinaryTree newData ) {
38
38
39
39
int cpr = newData .data .compareTo (this .data ); //new value comparission respect to actual value
40
40
41
- if (cpr < 0 ) {
42
- if (this .left == null ) {
41
+ if (cpr < 0 )
42
+ if (this .left == null )
43
43
this .setLeft (newData );
44
- } else {
44
+ else
45
45
this .left .insert (newData );
46
- }
47
- } else if (cpr > 0 ) {
48
- if (this .right == null ) {
46
+ else if (cpr > 0 )
47
+ if (this .right == null )
49
48
this .setRight (newData );
50
- } else {
49
+ else
51
50
this .right .insert (newData );
52
- }
53
- } else {
51
+ else
54
52
System .out .println ("Redundant value, not added" );
55
- }
56
53
}
57
54
58
55
/**
@@ -61,8 +58,8 @@ public void insert(BinaryTree<T> newData) {
61
58
* @param data Searched value
62
59
* @return Binary tree which contains the value, null if it doesn't exist
63
60
*/
64
- public BinaryTree < T > search (T data ) {
65
- int cpr = data .compareTo (this .data ); //new value comparison respect to actual value
61
+ public BinaryTree search (T data ) {
62
+ int cpr = data .compareTo (this .data ); //new value comparission respect to actual value
66
63
67
64
if (cpr < 0 ) {
68
65
if (this .left == null )
@@ -116,19 +113,19 @@ public T getData() {
116
113
return data ;
117
114
}
118
115
119
- public BinaryTree < T > getRight () {
116
+ public BinaryTree getRight () {
120
117
return right ;
121
118
}
122
119
123
- public void setRight (BinaryTree < T > right ) {
120
+ public void setRight (BinaryTree right ) {
124
121
this .right = right ;
125
122
}
126
123
127
- public BinaryTree < T > getLeft () {
124
+ public BinaryTree getLeft () {
128
125
return left ;
129
126
}
130
127
131
- public void setLeft (BinaryTree < T > left ) {
128
+ public void setLeft (BinaryTree left ) {
132
129
this .left = left ;
133
130
}
134
131
}
0 commit comments