Skip to content

Commit 10ab7fa

Browse files
committed
#Modification 12
1 parent 6b75cdf commit 10ab7fa

8 files changed

Lines changed: 41 additions & 37 deletions

array/KadanesAlgorithm.class

812 Bytes
Binary file not shown.
1.28 KB
Binary file not shown.

stack/Postfix.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,77 @@
11
package stack;
2+
23
import java.util.*;
4+
35
//Program to convert infix to postfix
4-
public class Postfix{
6+
public class Postfix {
57

6-
static int Prec(char ch){
7-
switch(ch){
8+
static int Prec(char ch) {
9+
switch (ch) {
810
case '+':
911
case '-':
1012
return 1;
11-
13+
1214
case '*':
1315
case '/':
1416
return 2;
15-
17+
1618
case '^':
1719
return 3;
1820
}
1921

2022
return -1;
2123
}
2224

23-
static String infixToPostfix(String exp){
25+
static String infixToPostfix(String exp) {
2426

2527
String result = new String(" ");
2628
Stack<Character> stack = new Stack<>();
2729

28-
for(int i = 0 ; i < exp.length() ; ++i){
30+
for (int i = 0; i < exp.length(); ++i) {
31+
2932
char c = exp.charAt(i);
3033

31-
if(Character.isLetterOrDigit(c))
34+
if (Character.isLetterOrDigit(c))
3235
result += c;
3336

34-
else if(c == '(')
37+
else if (c == '(')
3538
stack.push(c);
3639

37-
else if (c == ')'){
38-
while (!stack.isEmpty() && stack.peek() != '(')
39-
result += stack.pop();
40+
else if (c == ')') {
41+
while (!stack.isEmpty() && stack.peek() != '(')
42+
result += stack.pop();
4043

4144
stack.pop();
4245
}
4346

44-
else{
45-
while(!stack.isEmpty() && Prec(c) <= Prec(stack.peek())){
47+
else {
48+
while (!stack.isEmpty() && Prec(c) <= Prec(stack.peek())) {
4649
result += stack.pop();
47-
}
50+
}
4851
}
4952

5053
stack.push(c);
5154
}
5255

5356
while (!stack.isEmpty()) {
5457

55-
if(stack.peek() == '(')
58+
if (stack.peek() == '(')
5659
return "Invalid Expression";
5760

58-
result += stack.pop();
61+
result += stack.pop();
5962
}
6063

6164
return result;
6265
}
6366

6467
public static void main(String[] args) {
6568

69+
//Taking String "exe" input
6670
Scanner sc = new Scanner(System.in);
6771
String exp = sc.nextLine();
6872
sc.close();
6973

7074
Postfix p = new Postfix();
71-
72-
p = infixToPostfix(exp);
73-
System.out.println(p);
75+
System.out.println(infixToPostfix(exp));
7476
}
7577
}

stack/stack/Postfix.class

0 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: BinaryTree_Traversal","url":"c:\\Users\\AmanSoni\\Desktop\\Java Program's\\Java-Eclipse\\Placement Prepration\\src\\trees\\BinaryTree_Traversal.java","tests":[{"id":1608219457557,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\AmanSoni\\Desktop\\Java Program's\\Java-Eclipse\\Placement Prepration\\src\\trees\\BinaryTree_Traversal.java","group":"local","local":true}

trees/BinaryTree_Traversal.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package trees;
22

33
//java program for different tree traversals
4-
/*
5-
* Class containing left and right child of current node and key value
6-
*/
7-
//class Node{
8-
// int key;
9-
// Node left, right;
10-
//
11-
// public Node(int item) {
12-
// key = item;
13-
// left = right = null;
14-
// }
15-
//}
164

175
public class BinaryTree_Traversal {
6+
7+
/*
8+
* Class containing left and right child of current node and key value
9+
*/
10+
class Node{
11+
int key;
12+
Node left, right;
13+
14+
public Node(int item) {
15+
key = item;
16+
left = right = null;
17+
}
18+
}
1819

1920
//root of binary Tree
2021
Node root;
@@ -75,11 +76,11 @@ public static void main(String[] args) {
7576

7677
BinaryTree_Traversal tree = new BinaryTree_Traversal();
7778

78-
tree.root = new Node(1);
79-
tree.root.left = new Node(2);
80-
tree.root.right = new Node(3);
81-
tree.root.left.left = new Node(4);
82-
tree.root.left.right = new Node(5);
79+
tree.new Node(1);
80+
tree.new Node(2);
81+
tree.new Node(3);
82+
tree.new Node(4);
83+
tree.new Node(5);
8384

8485
System.out.println("Preorder traversal of binary tree is ");
8586
tree.printPreorder();
554 Bytes
Binary file not shown.
2.09 KB
Binary file not shown.

0 commit comments

Comments
 (0)