-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ec507a
commit 9ab4dc3
Showing
91 changed files
with
367 additions
and
93 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_20 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_21 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_22 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_23 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_24 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_25 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_26 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_27 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_28 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_29 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_30 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_32 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_33 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package binaryTree; | ||
|
||
public class BT_Problem_34 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.