1- package com .datastructures ;
1+ package com .dataStructures ;
22
33/**
44 * Binary tree for general value type, without redundancy
88
99public class BinaryTree <T extends Comparable > {
1010 private final T data ;
11- private BinaryTree < T > right , // the upper binary tree
11+ private BinaryTree right , // the upper binary tree
1212 left ; // the lower binary tree
1313
1414 public BinaryTree (T data ) {
@@ -21,38 +21,35 @@ public String toString() {
2121 }
2222
2323 /**
24- * inserts a new value in it's correspondent place
24+ * inserts a new value in it's correspondant place
2525 *
2626 * @param newDataValue value of the new binary tree to add on this tree
2727 */
2828 public void insert (T newDataValue ) {
29- this .insert (new BinaryTree <> (newDataValue ));
29+ this .insert (new BinaryTree (newDataValue ));
3030 }
3131
3232 /**
33- * inserts a new binary tree in it's correspondent place
33+ * inserts a new binary tree in it's correspondant place
3434 *
3535 * @param newData new value to add on this tree
3636 */
37- public void insert (BinaryTree < T > newData ) {
37+ public void insert (BinaryTree newData ) {
3838
3939 int cpr = newData .data .compareTo (this .data ); //new value comparission respect to actual value
4040
41- if (cpr < 0 ) {
42- if (this .left == null ) {
41+ if (cpr < 0 )
42+ if (this .left == null )
4343 this .setLeft (newData );
44- } else {
44+ else
4545 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 )
4948 this .setRight (newData );
50- } else {
49+ else
5150 this .right .insert (newData );
52- }
53- } else {
51+ else
5452 System .out .println ("Redundant value, not added" );
55- }
5653 }
5754
5855 /**
@@ -61,8 +58,8 @@ public void insert(BinaryTree<T> newData) {
6158 * @param data Searched value
6259 * @return Binary tree which contains the value, null if it doesn't exist
6360 */
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
6663
6764 if (cpr < 0 ) {
6865 if (this .left == null )
@@ -116,19 +113,19 @@ public T getData() {
116113 return data ;
117114 }
118115
119- public BinaryTree < T > getRight () {
116+ public BinaryTree getRight () {
120117 return right ;
121118 }
122119
123- public void setRight (BinaryTree < T > right ) {
120+ public void setRight (BinaryTree right ) {
124121 this .right = right ;
125122 }
126123
127- public BinaryTree < T > getLeft () {
124+ public BinaryTree getLeft () {
128125 return left ;
129126 }
130127
131- public void setLeft (BinaryTree < T > left ) {
128+ public void setLeft (BinaryTree left ) {
132129 this .left = left ;
133130 }
134131}
0 commit comments