Skip to content

Commit

Permalink
#Modification 30
Browse files Browse the repository at this point in the history
  • Loading branch information
amangit1314 committed May 7, 2021
1 parent 5ec507a commit 9ab4dc3
Show file tree
Hide file tree
Showing 91 changed files with 367 additions and 93 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion oopsabstraction/Audi.java → abstraction/Audi.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package oopsabstraction;
package abstraction;

//Audi Class
public class Audi extends Car{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion oopsabstraction/Car.java → abstraction/Car.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package oopsabstraction;
package abstraction;

public abstract class Car {
public abstract void accelerate();
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions abstraction/RepairShop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package abstraction;

public class RepairShop {

public static void repairCar(Car car) {
System.out.println("Car is repaired");
}

public static void repairCar(Car...Audi) {
System.out.println("Car is repaired");
}

public static void main(String[] args) {
WagonR wagonR = new WagonR();
Audi audi = new Audi();

repairCar(wagonR);
repairCar(audi);
}
}
File renamed without changes.
14 changes: 14 additions & 0 deletions abstraction/WagonR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package abstraction;

public class WagonR extends Car{

@Override
public void accelerate() {
System.out.println("WagonR is accelerating");
}

@Override
public void apply_break() {
System.out.println("break is applied in WagonR");
}
}
35 changes: 28 additions & 7 deletions binaryTree/BT_Problem_10.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,47 @@
* The right view of a binary tree, is set of nodes visible when tree is visited from rights side
* between two end nodes.
*/
class Max_level{
int max_level;
}
public class BT_Problem_10 {

Node root;
static int max_level = 0;

void leftViewUtil(Node node, int level) {
Max_level max_level = new Max_level();

void rightViewUtil(Node node, int level, Max_level max_level) {

if(node == null)
return;

if(max_level < level) {
System.out.print(" " + node.data);
max_level = level;
if(max_level.max_level < level) {
System.out.print(node.data + " " );
max_level.max_level = level;
}


rightViewUtil(node.right, level+1,max_level);
rightViewUtil(node.left, level+1,max_level);
}

void rightView() {
rightView(root);
}

void rightView(Node node) {
rightViewUtil(node, 1, max_level);
}

public static void main(String[] args) {
BT_Problem_10 tree = new BT_Problem_10();
tree.root = new Node(12);
tree.root.left = new Node(10);
tree.root.right = new Node(30);
tree.root.right.left = new Node(25);
tree.root.right.right = new Node(40);

tree.rightView();


}

}
2 changes: 1 addition & 1 deletion binaryTree/BT_Problem_15.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import java.util.*;
import java.util.Map.Entry;
/*
* Problem Title :- Diagnol Traversal of a Binary tree
* Problem Title :- Daignol Traversal of a Binary tree
*/
public class BT_Problem_15 {

Expand Down
84 changes: 80 additions & 4 deletions binaryTree/BT_Problem_17.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,86 @@
package binaryTree;

import java.util.*;
/*
* Problem Title :- Construct Binary Tree from String with Bracket Representation.
*/
public class BT_Problem_17 {

// Binary Tree node
static class Node{
int data;
Node left, right;
};

// Helper function that allocates a new node
static Node newNode(int data) {
Node node = new Node();
node.data = data;
node.left = node.right = null;
return(node);
}

// function just for testing
static void preOrder(Node node) {
if(node == null)
return;
System.out.printf("%d ", node.data);
preOrder(node.left);
preOrder(node.right);
}

// function to return the index of close parenthesis
static int findIndex(String str, int si, int ei) {
// base case
if(si > ei)
return -1;
//Inbuilt Stack
Stack<Character> s = new Stack<>();
// loop for iterations of the index
for(int i = si; i <= ei; i++) {
// if open parenthesis, push it to the stack
if(str.charAt(i) == '(')
s.add(str.charAt(i));
// if close parenthesis, pop it and else stack is empty that will be the required index
else if(str.charAt(i) == ')') {
if(s.peek() == '(') {
// pop from stack
s.pop();
//if stack is empty, this is the required index
if(s.isEmpty()) return i;
}
}
}
return -1;
}

// function to construct tree from string
static Node treeFromString(String str, int si, int ei) {

// Base Case
if(si > ei) return null;

// new root
Node root = newNode(str.charAt(si) - '0');
int index = -1;

// if next char is '(' find the index of its complement
if(si + 1 <= ei && str.charAt(si+1) == '(')
index = findIndex(str, si + 1, ei);

// if index found
if(index != -1) {
// call for left subtree
root.left = treeFromString(str, si+2, index - 1);
// call for left subtree
root.right = treeFromString(str, index + 2, ei - 1);
}
return root;
}

//Driver Code
public static void main(String[] args) {
// TODO Auto-generated method stub

String str = "4(2(3)(1))(6(5))";
Node root = treeFromString(str, 0, str.length() - 1);
preOrder(root);
}

}
5 changes: 3 additions & 2 deletions binaryTree/BT_Problem_18.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package binaryTree;

/*
* Problem Title :- Convert Binary tree into Doubly Linked List
*/
public class BT_Problem_18 {

public static void main(String[] args) {
// TODO Auto-generated method stub

}

Expand Down
4 changes: 3 additions & 1 deletion binaryTree/BT_Problem_19.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package binaryTree;

/*
* Problem Title :- Construct Binary Tree from String with Bracket Representation.
*/
public class BT_Problem_19 {

public static void main(String[] args) {
Expand Down
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_20.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_20 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_21.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_21 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_22.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_22 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_23.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_23 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_24.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_24 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_25.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_25 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_26.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_26 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_27.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_27 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_28.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_28 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_29.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_29 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_30.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_30 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_32.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_32 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_33.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_33 {

}
5 changes: 5 additions & 0 deletions binaryTree/BT_Problem_34.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package binaryTree;

public class BT_Problem_34 {

}
7 changes: 4 additions & 3 deletions bitManipulation/BM_02.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bitManipulation;

/*
* Problem Title :- Find the two non-repeating elements in an array of repeating elements
*/
public class BM_02 {

public static void main(String[] args) {
// TODO Auto-generated method stub


}

}
4 changes: 3 additions & 1 deletion bitManipulation/BM_03.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Count number of bits to be flipped to convert A to B
*/
public class BM_03 {

public static void main(String[] args) {
Expand Down
4 changes: 3 additions & 1 deletion bitManipulation/BM_04.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Count total set bits in all numbers from 1 to n
*/
public class BM_04 {

public static void main(String[] args) {
Expand Down
4 changes: 3 additions & 1 deletion bitManipulation/BM_05.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Program to find whether a no is power of two
*/
public class BM_05 {

public static void main(String[] args) {
Expand Down
4 changes: 3 additions & 1 deletion bitManipulation/BM_06.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Find position of the only set bit
*/
public class BM_06 {

public static void main(String[] args) {
Expand Down
4 changes: 3 additions & 1 deletion bitManipulation/BM_07.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Copy set bits in a range
*/
public class BM_07 {

public static void main(String[] args) {
Expand Down
4 changes: 3 additions & 1 deletion bitManipulation/BM_08.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Divide two integers without using multiplication, division and mod operator
*/
public class BM_08 {

public static void main(String[] args) {
Expand Down
4 changes: 3 additions & 1 deletion bitManipulation/BM_09.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bitManipulation;

/*
* Problem Title :- Calculate square of a number without using *, / and pow()
*/
public class BM_09 {

public static void main(String[] args) {
Expand Down
Loading

0 comments on commit 9ab4dc3

Please sign in to comment.