File tree Expand file tree Collapse file tree 4 files changed +58
-3
lines changed Expand file tree Collapse file tree 4 files changed +58
-3
lines changed 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: 6:36 PM
8+ * To change this template go to Preferences | IDE Settings | File and Code Templates
9+ */
10+ public class BinarySearchTree <E > extends BinaryTree <E > {
11+
12+ }
Original file line number Diff line number Diff line change 1+ package me .ramswaroop .trees ;
2+
3+ import me .ramswaroop .common .BinaryNode ;
4+
5+ /**
6+ * Created by IntelliJ IDEA.
7+ * User: ramswaroop
8+ * Date: 4/19/15
9+ * Time: 6:35 PM
10+ * To change this template go to Preferences | IDE Settings | File and Code Templates
11+ */
12+ public class BinaryTree <E > extends Tree <E > {
13+ public static <E > boolean isIdentical (BinaryNode <E > node1 , BinaryNode <E > node2 ) {
14+ return false ;
15+ }
16+ }
Original file line number Diff line number Diff line change 11package me .ramswaroop .trees ;
22
33import me .ramswaroop .common .BinaryNode ;
4+ import me .ramswaroop .utils .Utils ;
45
56/**
67 * Created by IntelliJ IDEA.
910 * Time: 3:02 PM
1011 * To change this template go to Preferences | IDE Settings | File and Code Templates
1112 */
12- public class RecursiveBST <E extends Comparable <E >> {
13+ public class RecursiveBST <E extends Comparable <E >> extends Tree {
1314
1415 BinaryNode root ;
1516
@@ -24,6 +25,7 @@ public static void main(String[] a) {
2425 obj .inOrder ();
2526 obj .print ("\n " );
2627 obj .postOrder ();
28+ Utils .println ("\n " + obj .size ());
2729 }
2830
2931 /**
@@ -118,7 +120,15 @@ public void postOrder(BinaryNode<E> node) {
118120 * @return
119121 */
120122 public int size () {
121- return 0 ;
123+ return size (root );
124+ }
125+
126+ public int size (BinaryNode <E > node ) {
127+ if (node == null ) {
128+ return 0 ;
129+ } else {
130+ return size (node .left ) + 1 + size (node .right );
131+ }
122132 }
123133
124134 /**
@@ -127,9 +137,14 @@ public int size() {
127137 * @return
128138 */
129139 public boolean isEmpty () {
130- return false ;
140+ return root == null ;
131141 }
132142
143+ /**
144+ * Utility methods
145+ *
146+ * @param value
147+ */
133148 private void print (E value ) {
134149 System .out .print (value );
135150 }
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: 6:30 PM
8+ * To change this template go to Preferences | IDE Settings | File and Code Templates
9+ */
10+ public class Tree <E > {
11+
12+ }
You can’t perform that action at this time.
0 commit comments