File tree Expand file tree Collapse file tree 4 files changed +41
-6
lines changed Expand file tree Collapse file tree 4 files changed +41
-6
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public static void main(String[] args) {
1313 Scanner in = new Scanner (System .in );
1414 LinkedStack <Integer > stack = new LinkedStack <>();
1515 LinkedQueue <Integer > queue = new LinkedQueue <>();
16- firstLoop :
16+ chooseModule :
1717 while (true ) {
1818 Utils .println ("Choose module:" );
1919 Utils .println ("==============" );
@@ -52,7 +52,7 @@ public static void main(String[] args) {
5252 stack .print ();
5353 break ;
5454 case 5 :
55- continue firstLoop ;
55+ continue chooseModule ;
5656 default :
5757 Utils .println ("Wrong choice!" );
5858 }
@@ -86,7 +86,7 @@ public static void main(String[] args) {
8686 queue .print ();
8787 break ;
8888 case 5 :
89- continue firstLoop ;
89+ continue chooseModule ;
9090 default :
9191 Utils .println ("Wrong choice!" );
9292 }
Original file line number Diff line number Diff line change 1010 * To change this template go to Preferences | IDE Settings | File and Code Templates
1111 */
1212public class BinaryTree <E > extends Tree <E > {
13+ BinaryNode <E > root ;
14+
1315 public static <E > boolean isIdentical (BinaryNode <E > node1 , BinaryNode <E > node2 ) {
14- return false ;
16+ if (node1 == null && node2 == null ) return true ;
17+ if (node1 == null && node2 != null || (node1 != null && node2 == null )) return false ;
18+
19+ if (node1 .value == node2 .value ) {
20+ return true && isIdentical (node1 .left , node2 .left ) && isIdentical (node1 .right , node2 .right );
21+ } else {
22+ return false ;
23+ }
24+ }
25+
26+ public int height () {
27+ return height (root );
28+ }
29+
30+ public int height (BinaryNode <E > node ) {
31+ return 0 ;
32+ }
33+
34+ public boolean isIdentical (BinaryNode <E > node ) {
35+ return isIdentical (this .root , node );
1536 }
1637}
Original file line number Diff line number Diff line change 1+ package me .ramswaroop .trees ;
2+
3+ /**
4+ * Created by IntelliJ IDEA.
5+ * User: ramswaroop
6+ * Date: 4/19/15
7+ * Time: 11:41 PM
8+ * To change this template go to Preferences | IDE Settings | File and Code Templates
9+ */
10+ public class NonRecursiveBST <E extends Comparable <E >> extends BinarySearchTree <E > {
11+
12+ }
Original file line number Diff line number Diff line change 1010 * Time: 3:02 PM
1111 * To change this template go to Preferences | IDE Settings | File and Code Templates
1212 */
13- public class RecursiveBST <E extends Comparable <E >> extends Tree {
13+ public class RecursiveBST <E extends Comparable <E >> extends BinarySearchTree < E > {
1414
15- BinaryNode root ;
15+ // BinaryNode<E> root;
1616
1717 public static void main (String [] a ) {
1818 RecursiveBST obj = new RecursiveBST ();
@@ -26,6 +26,8 @@ public static void main(String[] a) {
2626 obj .print ("\n " );
2727 obj .postOrder ();
2828 Utils .println ("\n " + obj .size ());
29+ Utils .println (BinaryTree .isIdentical (obj .root .right , obj .root .right ));
30+ Utils .println (obj .isIdentical (obj .root ));
2931 }
3032
3133 /**
You can’t perform that action at this time.
0 commit comments