Skip to content

Commit db0fe15

Browse files
committed
New Programs
1 parent e709b60 commit db0fe15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+24929
-24664
lines changed

bin/Anagram.class

1013 Bytes
Binary file not shown.

bin/LCS.class

2.29 KB
Binary file not shown.

bin/Sort.class

3.39 KB
Binary file not shown.

bin/removeDuplicate.class

1.22 KB
Binary file not shown.

codingProblems/.classpath

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5-
<classpathentry kind="output" path="bin"/>
6-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

codingProblems/.project

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<projectDescription>
3-
<name>codingProblems</name>
4-
<comment></comment>
5-
<projects>
6-
</projects>
7-
<buildSpec>
8-
<buildCommand>
9-
<name>org.eclipse.jdt.core.javabuilder</name>
10-
<arguments>
11-
</arguments>
12-
</buildCommand>
13-
</buildSpec>
14-
<natures>
15-
<nature>org.eclipse.jdt.core.javanature</nature>
16-
</natures>
17-
</projectDescription>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>codingProblems</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
eclipse.preferences.version=1
2-
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4-
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5-
org.eclipse.jdt.core.compiler.compliance=1.8
6-
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7-
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8-
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11-
org.eclipse.jdt.core.compiler.source=1.8
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
/* All permutations of a given String
2-
* This algorithm taken O(n!) time since there are n! permutations possible */
3-
4-
package codingProblems;
5-
import java.util.ArrayList;
6-
import java.util.Scanner;
7-
8-
public class AllPermutationsOfString
9-
{
10-
public static void main(String args[])
11-
{
12-
Scanner in = new Scanner(System.in);
13-
System.out.println("Enter a string to find permutations:");
14-
System.out.println("All permutations:"+getPerm(in.next()));
15-
in.close();
16-
}
17-
public static ArrayList<String> getPerm(String s)
18-
{
19-
ArrayList<String> perm = new ArrayList<String>();
20-
if (s==null)
21-
return null; //Error condition
22-
else if(s.length() == 0) //base case
23-
{
24-
perm.add("");
25-
return perm;
26-
}
27-
28-
char c=s.charAt(0);
29-
String remainder = s.substring(1);
30-
ArrayList<String> words= getPerm(remainder);
31-
for(String word:words)
32-
{
33-
for(int i=0;i<= word.length();i++)
34-
{
35-
perm.add(insertCharAt(word, c, i));
36-
}
37-
}
38-
return perm;
39-
}
40-
public static String insertCharAt(String s, char c, int i)
41-
{
42-
String a=s.substring(0,i);
43-
String b=s.substring(i);
44-
return a+c+b;
45-
}
46-
}
1+
/* All permutations of a given String
2+
* This algorithm taken O(n!) time since there are n! permutations possible */
3+
4+
package codingProblems;
5+
import java.util.ArrayList;
6+
import java.util.Scanner;
7+
8+
public class AllPermutationsOfString
9+
{
10+
public static void main(String args[])
11+
{
12+
Scanner in = new Scanner(System.in);
13+
System.out.println("Enter a string to find permutations:");
14+
System.out.println("All permutations:"+getPerm(in.next()));
15+
in.close();
16+
}
17+
public static ArrayList<String> getPerm(String s)
18+
{
19+
ArrayList<String> perm = new ArrayList<String>();
20+
if (s==null)
21+
return null; //Error condition
22+
else if(s.length() == 0) //base case
23+
{
24+
perm.add("");
25+
return perm;
26+
}
27+
28+
char c=s.charAt(0);
29+
String remainder = s.substring(1);
30+
ArrayList<String> words= getPerm(remainder);
31+
for(String word:words)
32+
{
33+
for(int i=0;i<= word.length();i++)
34+
{
35+
perm.add(insertCharAt(word, c, i));
36+
}
37+
}
38+
return perm;
39+
}
40+
public static String insertCharAt(String s, char c, int i)
41+
{
42+
String a=s.substring(0,i);
43+
String b=s.substring(i);
44+
return a+c+b;
45+
}
46+
}
+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package codingProblems;
2-
import java.util.*;
3-
public class Anagram
4-
{
5-
public static boolean isAnagram(String firstWord, String secondWord)
6-
{
7-
char[] word1 = firstWord.replaceAll("[\\s]", "").toCharArray();
8-
char[] word2 = secondWord.replaceAll("[\\s]", "").toCharArray();
9-
Arrays.sort(word1);
10-
Arrays.sort(word2);
11-
return Arrays.equals(word1, word2);
12-
}
13-
public static void main(String args[]){
14-
System.out.println(isAnagram("abca","cbaa"));
15-
}
16-
}
1+
package codingProblems;
2+
import java.util.*;
3+
public class Anagram
4+
{
5+
public static boolean isAnagram(String firstWord, String secondWord)
6+
{
7+
char[] word1 = firstWord.replaceAll("[\\s]", "").toCharArray();
8+
char[] word2 = secondWord.replaceAll("[\\s]", "").toCharArray();
9+
Arrays.sort(word1);
10+
Arrays.sort(word2);
11+
return Arrays.equals(word1, word2);
12+
}
13+
public static void main(String args[]){
14+
System.out.println(isAnagram("abca","cbaa"));
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
package codingProblems;
2-
3-
import java.util.Arrays;
4-
import java.util.Comparator;
5-
6-
public class AnagramComparator implements Comparator<String>
7-
{
8-
public int compare(String s1, String s2)
9-
{
10-
return sortChars(s1).compareTo(sortChars(s2));
11-
}
12-
public String sortChars(String s)
13-
{
14-
char[] content = s.toCharArray();
15-
Arrays.sort(content);
16-
return new String(content);
17-
}
18-
public static void main(String[] args)
19-
{
20-
String[] strArray = new String[]{"abets","mates","baste","meats", "betas","beast", "steam", "tames", "beats", "teams"};
21-
sortArraysByAnagrams(strArray);
22-
for(String str : strArray){
23-
System.out.println(str);
24-
}
25-
26-
}
27-
private static void sortArraysByAnagrams(String[] strArray)
28-
{
29-
Arrays.sort(strArray, new AnagramComparator());
30-
}
31-
}
1+
package codingProblems;
2+
3+
import java.util.Arrays;
4+
import java.util.Comparator;
5+
6+
public class AnagramComparator implements Comparator<String>
7+
{
8+
public int compare(String s1, String s2)
9+
{
10+
return sortChars(s1).compareTo(sortChars(s2));
11+
}
12+
public String sortChars(String s)
13+
{
14+
char[] content = s.toCharArray();
15+
Arrays.sort(content);
16+
return new String(content);
17+
}
18+
public static void main(String[] args)
19+
{
20+
String[] strArray = new String[]{"abets","mates","baste","meats", "betas","beast", "steam", "tames", "beats", "teams"};
21+
sortArraysByAnagrams(strArray);
22+
for(String str : strArray){
23+
System.out.println(str);
24+
}
25+
26+
}
27+
private static void sortArraysByAnagrams(String[] strArray)
28+
{
29+
Arrays.sort(strArray, new AnagramComparator());
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
/*
2-
* Array Implementation of stack
3-
*/
4-
package codingProblems;
5-
6-
public class ArrayImplementationOfStack
7-
{
8-
private int top;
9-
int size;
10-
int[] stack ;
11-
12-
public ArrayImplementationOfStack(int arraySize)
13-
{
14-
size=arraySize;
15-
stack= new int[size];
16-
top=-1;
17-
}
18-
19-
public void push(int value)
20-
{
21-
if(top==size-1)
22-
{
23-
System.out.println("Stack is full, can't push a value");
24-
}
25-
else
26-
{
27-
top=top+1;
28-
stack[top]=value;
29-
}
30-
}
31-
32-
public void pop()
33-
{
34-
if(!isEmpty())
35-
top=top-1;
36-
else
37-
{
38-
System.out.println("Can't pop...stack is empty");
39-
}
40-
}
41-
42-
public boolean isEmpty()
43-
{
44-
return top==-1;
45-
}
46-
47-
public void display()
48-
{
49-
for(int i=0;i<=top;i++)
50-
{
51-
System.out.print(stack[i]+ " ");
52-
}
53-
System.out.println();
54-
}
1+
/*
2+
* Array Implementation of stack
3+
*/
4+
package codingProblems;
5+
6+
public class ArrayImplementationOfStack
7+
{
8+
private int top;
9+
int size;
10+
int[] stack ;
11+
12+
public ArrayImplementationOfStack(int arraySize)
13+
{
14+
size=arraySize;
15+
stack= new int[size];
16+
top=-1;
17+
}
18+
19+
public void push(int value)
20+
{
21+
if(top==size-1)
22+
{
23+
System.out.println("Stack is full, can't push a value");
24+
}
25+
else
26+
{
27+
top=top+1;
28+
stack[top]=value;
29+
}
30+
}
31+
32+
public void pop()
33+
{
34+
if(!isEmpty())
35+
top=top-1;
36+
else
37+
{
38+
System.out.println("Can't pop...stack is empty");
39+
}
40+
}
41+
42+
public boolean isEmpty()
43+
{
44+
return top==-1;
45+
}
46+
47+
public void display()
48+
{
49+
for(int i=0;i<=top;i++)
50+
{
51+
System.out.print(stack[i]+ " ");
52+
}
53+
System.out.println();
54+
}
5555
}

0 commit comments

Comments
 (0)