File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import me .ramswaroop .common .BinaryNode ;
44import me .ramswaroop .common .BinarySearchTree ;
5- import me .ramswaroop .common .BinaryTree ;
65
76import static java .lang .System .out ;
87
1312 * @date: 6/26/15
1413 * @time: 5:36 PM
1514 */
16- public class IdenticalTrees <E extends Comparable <E >> extends BinaryTree <E > {
17-
18- /**
19- * Checks whether this tree and another with {@param node}
20- * as root are identical or not.
21- *
22- * @param node
23- * @return
24- */
25- public boolean isIdentical (BinaryNode <E > node ) {
26- return isIdentical (this .root , node );
27- }
15+ public class IdenticalTrees {
2816
2917 /**
3018 * Checks whether two trees having their roots at node1 and node2
Original file line number Diff line number Diff line change 1414 * @date: 6/26/15
1515 * @time: 7:31 PM
1616 */
17- public class InOrderUsingStack <E extends Comparable <E >> extends BinarySearchTree <E > {
18-
19- public void inOrder () {
20- inOrderUsingStack (root );
21- }
17+ public class InOrderUsingStack {
2218
2319 /**
2420 * In-order traversal of tree using one stack and without recursion.
2521 *
2622 * @param node
2723 */
28- public void inOrderUsingStack (BinaryNode <E > node ) {
24+ public static < E extends Comparable < E >> void inOrderUsingStack (BinaryNode <E > node ) {
2925 if (node == null ) return ;
3026
3127 Stack <BinaryNode <E >> stack = new LinkedStack <>();
@@ -48,13 +44,13 @@ public void inOrderUsingStack(BinaryNode<E> node) {
4844 }
4945
5046 public static void main (String a []) {
51- InOrderUsingStack <Integer > bst = new InOrderUsingStack <>();
47+ BinarySearchTree <Integer > bst = new BinarySearchTree <>();
5248 bst .put (6 );
5349 bst .put (3 );
5450 bst .put (5 );
5551 bst .put (7 );
5652 bst .put (8 );
5753 bst .put (9 );
58- bst .inOrder ( );
54+ inOrderUsingStack ( bst .root );
5955 }
6056}
You can’t perform that action at this time.
0 commit comments