Skip to content

Commit 59bfb0f

Browse files
author
Ram swaroop
committed
changed to static import for System.out
1 parent f76fd8a commit 59bfb0f

3 files changed

Lines changed: 42 additions & 45 deletions

File tree

‎src/me/ramswaroop/trees/BinaryTree.java‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package me.ramswaroop.trees;
22

33
import me.ramswaroop.common.*;
4-
import me.ramswaroop.utils.Utils;
54

65
import java.util.ArrayList;
76
import java.util.EmptyStackException;
87
import java.util.List;
98
import java.util.NoSuchElementException;
109

10+
import static java.lang.System.out;
11+
1112
/**
1213
* Created by IntelliJ IDEA.
1314
* User: ramswaroop
@@ -35,14 +36,14 @@ public static void main(String[] a) {
3536
binaryTree.put(5);
3637
binaryTree.put(1);
3738
binaryTree.put(1);
38-
Utils.print("Breadth-first Traversal: ");
39+
out.print("Breadth-first Traversal: ");
3940
binaryTree.breadthFirstTraversal();
40-
Utils.print("\nSpiral Traversal: ");
41+
out.print("\nSpiral Traversal: ");
4142
binaryTree.spiralTraversal();
42-
Utils.print("\nIn order traversal: ");
43+
out.print("\nIn order traversal: ");
4344
binaryTree.inOrder();
44-
Utils.print("\nIs BST: " + binaryTree.isBST());
45-
Utils.print("\nIs Children Sum : " + binaryTree.isChildrenSum());
45+
out.print("\nIs BST: " + binaryTree.isBST());
46+
out.print("\nIs Children Sum : " + binaryTree.isChildrenSum());
4647
}
4748

4849
/**
@@ -86,7 +87,7 @@ public void preOrder(BinaryNode<E> node) {
8687
if (node == null) {
8788
return;
8889
}
89-
Utils.print(node.value);
90+
out.print(node.value);
9091
preOrder(node.left);
9192
preOrder(node.right);
9293
}
@@ -104,7 +105,7 @@ public void inOrder(BinaryNode<E> node) {
104105
return;
105106
}
106107
inOrder(node.left);
107-
Utils.print(node.value);
108+
out.print(node.value);
108109
inOrder(node.right);
109110
}
110111

@@ -122,7 +123,7 @@ public void postOrder(BinaryNode<E> node) {
122123
}
123124
postOrder(node.left);
124125
postOrder(node.right);
125-
Utils.print(node.value);
126+
out.print(node.value);
126127
}
127128

128129

@@ -420,10 +421,10 @@ public void rootToLeafPaths(BinaryNode<E> node, E[] pathList, int pathLength) {
420421
if (node.left == null && node.right == null) {
421422
int i;
422423
for (i = 0; i < pathLength - 1; i++) {
423-
Utils.print(pathList[i] + " -> ");
424+
out.print(pathList[i] + " -> ");
424425
}
425426
// outside the loop so that "->" doesn't appear after the last node
426-
Utils.println(pathList[i]);
427+
out.println(pathList[i]);
427428
} else {
428429
// do the same for subtrees
429430
rootToLeafPaths(node.left, pathList, pathLength);
@@ -444,10 +445,10 @@ public void rootToLeafPaths(BinaryNode<E> node, List<E> pathList) {
444445
if (node.left == null && node.right == null) {
445446
int i;
446447
for (i = 0; i < pathList.size() - 1; i++) {
447-
Utils.print(pathList.get(i) + " -> ");
448+
out.print(pathList.get(i) + " -> ");
448449
}
449450
// outside the loop so that "->" doesn't appear after the last node
450-
Utils.println(pathList.get(i));
451+
out.println(pathList.get(i));
451452
} else {
452453
// do the same for subtrees
453454
rootToLeafPaths(node.left, new ArrayList<>(pathList));
@@ -576,6 +577,6 @@ public boolean isChildrenSum(BinaryNode<E> node) {
576577
protected void printValue(BinaryNode<E> node) {
577578
if (node == null) return;
578579

579-
Utils.print(node.value);
580+
out.print(node.value);
580581
}
581582
}

‎src/me/ramswaroop/trees/RecursiveBST.java‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package me.ramswaroop.trees;
22

33
import me.ramswaroop.common.BinaryNode;
4-
import me.ramswaroop.utils.Utils;
54

65
import java.util.NoSuchElementException;
76

7+
import static java.lang.System.out;
8+
89
/**
910
* Created by IntelliJ IDEA.
1011
* User: ramswaroop
@@ -23,33 +24,33 @@ public static void main(String[] a) {
2324
bst.put(8);
2425
bst.put(9);
2526
bst.preOrder();
26-
Utils.println("");
27+
out.println("");
2728
bst.inOrder();
28-
Utils.println("");
29+
out.println("");
2930
bst.postOrder();
30-
Utils.println("\n" + bst.size());
31-
Utils.println(BinaryTree.isIdentical(bst.root.right, bst.root.right));
32-
Utils.println(bst.isIdentical(bst.root));
33-
Utils.println(bst.height());
31+
out.println("\n" + bst.size());
32+
out.println(BinaryTree.isIdentical(bst.root.right, bst.root.right));
33+
out.println(bst.isIdentical(bst.root));
34+
out.println(bst.height());
3435
/*obj.delete();
35-
Utils.println("After deletion: ");
36+
out.println("After deletion: ");
3637
obj.postOrder();*/
37-
Utils.println("In Order: ");
38+
out.println("In Order: ");
3839
bst.inOrder();
39-
/*Utils.println("\nAfter mirroring: ");
40+
/*out.println("\nAfter mirroring: ");
4041
obj.mirror();
4142
obj.inOrder();*/
42-
Utils.println("\nRoot to leafs: ");
43+
out.println("\nRoot to leafs: ");
4344
bst.rootToLeafPaths();
44-
Utils.println("LCA: " + bst.leastCommonAncestor(bst.root, 6, 8).value);
45-
Utils.println("Min: " + bst.min().value);
46-
Utils.println("BFS: ");
45+
out.println("LCA: " + bst.leastCommonAncestor(bst.root, 6, 8).value);
46+
out.println("Min: " + bst.min().value);
47+
out.println("BFS: ");
4748
bst.breadthFirstTraversal();
48-
Utils.println("\nBFS using queue: ");
49+
out.println("\nBFS using queue: ");
4950
bst.breadthFirstTraversalUsingQueue();
50-
Utils.println("\nNo. of leaf nodes: " + bst.countLeafNodes());
51-
Utils.println("Is BST: " + bst.isBST());
52-
Utils.print("Tree to list: ");
51+
out.println("\nNo. of leaf nodes: " + bst.countLeafNodes());
52+
out.println("Is BST: " + bst.isBST());
53+
out.print("Tree to list: ");
5354
bst.treeToList();
5455
}
5556

@@ -119,11 +120,11 @@ public BinaryNode<E> min(BinaryNode<E> node) {
119120
public void leastCommonAncestor() {
120121
/*int value1, value2;
121122
Scanner in = new Scanner(System.in);
122-
Utils.println("Enter value 1: ");
123+
out.println("Enter value 1: ");
123124
value1 = (E) Integer.valueOf(in.nextLine());
124-
Utils.println("Enter value 1: ");
125+
out.println("Enter value 1: ");
125126
value2 = (E) in.nextLine();
126-
Utils.println("LCA of " + value1 + " and " + value2 + " is: " + leastCommonAncestor(root, value1, value2).value);*/
127+
out.println("LCA of " + value1 + " and " + value2 + " is: " + leastCommonAncestor(root, value1, value2).value);*/
127128
}
128129

129130
public BinaryNode<E> leastCommonAncestor(BinaryNode<E> node, E value1, E value2) {
@@ -193,15 +194,15 @@ private BinaryNode<E> addToList(BinaryNode<E> aList, BinaryNode<E> bList) {
193194

194195
private void printList(BinaryNode<E> node) {
195196
BinaryNode<E> current = node;
196-
Utils.print("[");
197+
out.print("[");
197198
if (current == null) {
198-
System.out.println("]");
199+
out.println("]");
199200
return;
200201
}
201202
while (current.right != node) {
202-
Utils.print(current.value + ",");
203+
out.print(current.value + ",");
203204
current = current.right;
204205
}
205-
Utils.println(current.value + "]");
206+
out.println(current.value + "]");
206207
}
207208
}

‎src/me/ramswaroop/utils/Utils.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,5 @@
88
* To change this template go to Preferences | IDE Settings | File and Code Templates
99
*/
1010
public class Utils {
11-
public static void print(Object o) {
12-
System.out.print(o);
13-
}
14-
public static void println(Object o) {
15-
System.out.println(o);
16-
}
11+
1712
}

0 commit comments

Comments
 (0)