Skip to content

Commit 5287259

Browse files
author
manjunatha
committed
Code arranged
1 parent f4b9794 commit 5287259

14 files changed

+42
-37
lines changed

datastructure/tree/bst/ConvertBTtoBST.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datastructure.tree.Node;
88

99
/**
10+
* Convert BT to BST
1011
* @author Manjunath Asundi
1112
*/
1213
class InnerConvertBTtoBST {
@@ -43,10 +44,7 @@ static void convertBTtoBST(Node<Integer> tree) {
4344
}
4445
}
4546

46-
/**
47-
* ConvertBTtoBST
48-
* link https://www.geeksforgeeks.org/binary-tree-to-binary-search-tree-conversion/
49-
*/
47+
5048
public class ConvertBTtoBST {
5149
public static void main(String[] args) {
5250
Node<Integer> tree = new Node<Integer>(10);

datastructure/tree/bst/GreaterSumTree.java

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ static void printInInOrder(Node<Integer> tree) {
2929

3030
/**
3131
* GreaterSumTree
32-
* link https://www.geeksforgeeks.org/transform-bst-sum-tree/
3332
*/
3433
public class GreaterSumTree {
3534
public static void main(String[] args) {

datastructure/tree/checktree/CheckSumTree.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datastructure.tree.Node;
44

55
/**
6-
* @author Manjunath Asundi
6+
* @author Manjunath Asundi
77
*/
88
class ChildrenSumOfTree {
99
static int isRootChildrenSum(Node<Integer> tree) {

datastructure/tree/constructtree/InAndLevel.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import datastructure.tree.Node;
44

55
/**
6-
* @author Manjunath Asundi
6+
* Given In And Preorder, print post order.
7+
*
8+
* @author Manjunath Asundi
79
*/
810
class ConstructTree {
911
static Node<Integer> buildTree(int inOrder[], int levelOrder[], int inStart, int inEnd) {
@@ -37,9 +39,6 @@ static void printTreeInPostOrder(Node<Integer> tree) {
3739
}
3840
}
3941

40-
/**
41-
* InAndPreorder
42-
*/
4342
public class InAndLevel {
4443
public static void main(String[] args) {
4544
int inOrder[] = { 4, 8, 10, 12, 14, 20, 22 };

datastructure/tree/constructtree/InAndPreorder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datastructure.tree.Node;
44

55
/**
6-
* @author Manjunath Asundi
6+
* @author Manjunath Asundi
77
*/
88
class BuildTree {
99
static int preIndex = 0;

datastructure/tree/constructtree/LevelToTree.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import datastructure.tree.Node;
44

55
/**
6-
* @author Manjunath Asundi
6+
* @author Manjunath Asundi
77
*/
88
class ConstructFromLevelOrder {
99
static int levelIndex = 0;
10+
1011
static Node<Integer> constructTreeFromLevelOrder(int levelOrder[], int level) {
11-
if(level >= levelOrder.length) return null;
12+
if (level >= levelOrder.length)
13+
return null;
1214
Node<Integer> tNode = new Node<Integer>(levelOrder[level]);
13-
tNode.left = constructTreeFromLevelOrder(levelOrder, (level*2)+1);
14-
tNode.right = constructTreeFromLevelOrder(levelOrder, (level*2)+2);
15+
tNode.left = constructTreeFromLevelOrder(levelOrder, (level * 2) + 1);
16+
tNode.right = constructTreeFromLevelOrder(levelOrder, (level * 2) + 2);
1517
return tNode;
1618
}
1719

datastructure/tree/constructtree/PreOrderToTree.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ class Index {
77
}
88

99
/**
10-
* @author Manjunath Asundi
1110
* Construct tree from given preorder
11+
*
12+
* @author Manjunath Asundi
1213
*/
1314
public class PreOrderToTree {
1415

datastructure/tree/converttree/ConverstToSumTree.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import datastructure.tree.Node;
44

55
/**
6-
* @author Manjunath Asundi
6+
* @author Manjunath Asundi
77
*/
88
class SumTree {
99
static int constructSumTree(Node<Integer> tree) {
10-
if(tree == null) return 0;
10+
if (tree == null)
11+
return 0;
1112
int temp = tree.data;
1213
tree.data = constructSumTree(tree.left) + constructSumTree(tree.right);
1314
return temp + tree.data;
@@ -20,15 +21,16 @@ static int constructSumTree(Node<Integer> tree) {
2021
public class ConverstToSumTree {
2122

2223
static void printInPreOrder(Node<Integer> tree) {
23-
if(tree == null) return;
24-
System.out.print(tree.data+" ");
24+
if (tree == null)
25+
return;
26+
System.out.print(tree.data + " ");
2527
printInPreOrder(tree.left);
2628
printInPreOrder(tree.right);
27-
}
29+
}
2830

2931
public static void main(String[] args) {
3032
Node<Integer> tree = new Node<Integer>(10);
31-
tree.left = new Node<Integer>(-2);
33+
tree.left = new Node<Integer>(-2);
3234
tree.right = new Node<Integer>(6);
3335
tree.left.left = new Node<Integer>(8);
3436
tree.left.left.left = new Node<Integer>(10);

datastructure/tree/converttree/convertToSumOfLeftSubTree.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package datastructure.tree.converttree;
22

33
import datastructure.tree.Node;
4+
45
/**
5-
* @author Manjunath Asundi
6+
* convert To Sum Of Left SubTree
7+
* @author Manjunath Asundi
68
*/
79
class SumOfLeftTree {
810
static int constructSumTree(Node<Integer> tree) {

datastructure/tree/traversal/LevelOrderTraversal.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* Level order traversal of tree
10+
*
1011
* @author Manjunath Asundi
1112
*/
1213
public class LevelOrderTraversal {

datastructure/tree/traversal/TraversalSpecific.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* Traverse tree in specific order
10+
*
1011
* @author Manjunath Asundi
1112
*/
1213
public class TraversalSpecific {

files/ParsingProgram.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* Parsing different computer programming language's program
12+
*
1213
* @author Manjunath Asundi
1314
*/
1415
public class ParsingProgram {
@@ -18,8 +19,10 @@ public class ParsingProgram {
1819
*/
1920
static class ParseData implements Runnable {
2021

21-
static int blankCount = 0, commentsCount = 0, codeCount = 0, totalLinesCount = 0, importCount = 0, variableDeclarationCount = 0;
22+
static int blankCount = 0, commentsCount = 0, codeCount = 0, totalLinesCount = 0, importCount = 0,
23+
variableDeclarationCount = 0;
2224
static String fileContent = null;
25+
2326
public ParseData(String data) {
2427
ParseData.fileContent = data;
2528
}
@@ -51,9 +54,10 @@ else if (line.startsWith("//") || line.startsWith("/*")) {
5154
}
5255
commentsCount++;
5356
} else {
54-
if(line.startsWith("import")) {
57+
if (line.startsWith("import")) {
5558
importCount++;
56-
} else if(line.startsWith("int") || line.startsWith("float") || line.startsWith("char") || line.startsWith("String"))
59+
} else if (line.startsWith("int") || line.startsWith("float") || line.startsWith("char")
60+
|| line.startsWith("String"))
5761
variableDeclarationCount++;
5862
codeCount++;
5963
}
@@ -64,7 +68,6 @@ public ParseData() {
6468
}
6569
}
6670

67-
6871
public static void main(String[] args) {
6972
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(20);
7073
try {
@@ -73,9 +76,8 @@ public static void main(String[] args) {
7376
for (int i = 0; i < filesList.length; i++) {
7477
if (filesList[i].endsWith(".java")) {
7578
System.out.println(filesList[i]);
76-
String data = Files
77-
.lines(Paths.get(
78-
"/Users/m0a07xh/Projects/Data-structure-And-Algorithms-using-Java/files/" + filesList[i]))
79+
String data = Files.lines(Paths.get(
80+
"/Users/m0a07xh/Projects/Data-structure-And-Algorithms-using-Java/files/" + filesList[i]))
7981
.collect(Collectors.joining(System.lineSeparator()));
8082
// System.out.println(data);
8183
executor.execute(new ParseData(data));
@@ -84,8 +86,8 @@ public static void main(String[] args) {
8486
executor.shutdown();
8587
while (!executor.isTerminated()) {
8688
}
87-
System.out.println("blankCount:" + ParseData.blankCount + " commentsCount:" + ParseData.commentsCount + " codeCount:"
88-
+ ParseData.codeCount + " totalLinesCount:" + ParseData.totalLinesCount);
89+
System.out.println("blankCount:" + ParseData.blankCount + " commentsCount:" + ParseData.commentsCount
90+
+ " codeCount:" + ParseData.codeCount + " totalLinesCount:" + ParseData.totalLinesCount);
8991
} catch (Exception e) {
9092
e.printStackTrace();
9193
}

multithreads/InterThreadCommunication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public synchronized void withDraw(int withDrawMoney) {
2525
}
2626

2727
public synchronized void deposit(int depositMoney) {
28-
while (iteration2 != 0 && iteration!=0) {
28+
while (iteration2 != 0 && iteration != 0) {
2929
amount += depositMoney;
3030
System.out.println("Amount deposited " + depositMoney + " succeessfully, balance amount:" + amount);
3131
notify();

util/ArrayUtil.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
public class ArrayUtil {
1111

1212
public static void printArray(int arr[]) {
13-
for (int data : arr) {
13+
for (int data : arr)
1414
System.out.print(data + " ");
15-
}
1615
System.out.println();
1716
}
1817

1918
public static void printList(List list) {
20-
for (Object object : list) {
19+
for (Object object : list)
2120
System.out.print(object + " ");
22-
}
2321
System.out.println();
2422
}
2523
}

0 commit comments

Comments
 (0)