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 > {
1010private final T data ;
11- private BinaryTree < T > right ,// the upper binary tree
11+ private BinaryTree right ,// the upper binary tree
1212left ;// the lower binary tree
1313
1414public BinaryTree (T data ) {
@@ -21,38 +21,35 @@ public String toString() {
2121 }
2222
2323/**
24- * inserts a new value in it'scorrespondent place
24+ * inserts a new value in it'scorrespondant place
2525 *
2626 * @param newDataValue value of the new binary tree to add on this tree
2727 */
2828public 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'scorrespondent place
33+ * inserts a new binary tree in it'scorrespondant 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
3939int 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 )
4343this .setLeft (newData );
44- } else {
44+ else
4545this .left .insert (newData );
46- }
47- }else if (cpr >0 ) {
48- if (this .right ==null ) {
46+ else if (cpr >0 )
47+ if (this .right ==null )
4948this .setRight (newData );
50- } else {
49+ else
5150this .right .insert (newData );
52- }
53- }else {
51+ else
5452System .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 valuecomparison respect to actual value
61+ public BinaryTree search (T data ) {
62+ int cpr =data .compareTo (this .data );//new valuecomparission respect to actual value
6663
6764if (cpr <0 ) {
6865if (this .left ==null )
@@ -116,19 +113,19 @@ public T getData() {
116113return data ;
117114 }
118115
119- public BinaryTree < T > getRight () {
116+ public BinaryTree getRight () {
120117return right ;
121118 }
122119
123- public void setRight (BinaryTree < T > right ) {
120+ public void setRight (BinaryTree right ) {
124121this .right =right ;
125122 }
126123
127- public BinaryTree < T > getLeft () {
124+ public BinaryTree getLeft () {
128125return left ;
129126 }
130127
131- public void setLeft (BinaryTree < T > left ) {
128+ public void setLeft (BinaryTree left ) {
132129this .left =left ;
133130 }
134131}