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 right ,// the upper binary tree
11+ private BinaryTree < T > right ,// the upper binary tree
1212left ;// the lower binary tree
1313
1414public BinaryTree (T data ) {
@@ -21,35 +21,38 @@ public String toString() {
2121 }
2222
2323/**
24- * inserts a new value in it'scorrespondant place
24+ * inserts a new value in it'scorrespondent 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'scorrespondant place
33+ * inserts a new binary tree in it'scorrespondent place
3434 *
3535 * @param newData new value to add on this tree
3636 */
37- public void insert (BinaryTree newData ) {
37+ public void insert (BinaryTree < T > 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- else if (cpr >0 )
47- if (this .right ==null )
46+ }
47+ }else if (cpr >0 ) {
48+ if (this .right ==null ) {
4849this .setRight (newData );
49- else
50+ } else {
5051this .right .insert (newData );
51- else
52+ }
53+ }else {
5254System .out .println ("Redundant value, not added" );
55+ }
5356 }
5457
5558/**
@@ -58,8 +61,8 @@ else if (cpr > 0)
5861 * @param data Searched value
5962 * @return Binary tree which contains the value, null if it doesn't exist
6063 */
61- public BinaryTree search (T data ) {
62- int cpr =data .compareTo (this .data );//new valuecomparission respect to actual value
64+ public BinaryTree < T > search (T data ) {
65+ int cpr =data .compareTo (this .data );//new valuecomparison respect to actual value
6366
6467if (cpr <0 ) {
6568if (this .left ==null )
@@ -113,19 +116,19 @@ public T getData() {
113116return data ;
114117 }
115118
116- public BinaryTree getRight () {
119+ public BinaryTree < T > getRight () {
117120return right ;
118121 }
119122
120- public void setRight (BinaryTree right ) {
123+ public void setRight (BinaryTree < T > right ) {
121124this .right =right ;
122125 }
123126
124- public BinaryTree getLeft () {
127+ public BinaryTree < T > getLeft () {
125128return left ;
126129 }
127130
128- public void setLeft (BinaryTree left ) {
131+ public void setLeft (BinaryTree < T > left ) {
129132this .left =left ;
130133 }
131134}