forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JavaDoc to every package except for "heaps"
- Loading branch information
1 parent
94871b7
commit 9411d5b
Showing
29 changed files
with
1,408 additions
and
427 deletions.
There are no files selected for viewing
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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry excluding="data_structures/" kind="src" path=""/> | ||
<classpathentry kind="src" path="data_structures"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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 @@ | ||
/bin/ |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Java</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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,74 @@ | ||
import java.util.Scanner; | ||
|
||
/** | ||
* Implements a Binary Search in Java | ||
* | ||
* @author unknown | ||
*/ | ||
class BinarySearch | ||
{ | ||
/** | ||
* This method implements the Binary Search | ||
* | ||
* @param array The array to make the binary search | ||
* @param key The number you are looking for | ||
* @param lb The lower bound | ||
* @param up The upper bound | ||
* @return the location of the key | ||
**/ | ||
public static int BS(int array[], int key, int lb, int ub) | ||
{ if (lb>ub) | ||
{ | ||
return -1; | ||
} | ||
|
||
int mid=(lb+ub)/2; | ||
|
||
if (key<array[mid]) | ||
{ | ||
return (BS(array, key, lb, mid-1)); | ||
} | ||
else if (key>array[mid]) | ||
{ | ||
return (BS(array, key, mid+1, ub)); | ||
} | ||
else | ||
{ | ||
return mid; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This is the main method of Binary Search | ||
* | ||
* @author Unknown | ||
* @param args Command line parameters | ||
*/ | ||
|
||
public static void main(String[] args) | ||
{ | ||
Scanner input=new Scanner(System.in); | ||
int array[]=new int[10] ; | ||
int key; | ||
|
||
//Input | ||
System.out.println("Enter an array of 10 numbers : "); | ||
for (int i=0; i<10 ;i++ ) | ||
{ | ||
array[i]=input.nextInt(); | ||
} | ||
System.out.println("Enter the number to be searched : "); | ||
key=input.nextInt(); | ||
|
||
int index=BS(array, key, 0, 9); | ||
if (index!=-1) | ||
{ | ||
System.out.println("Number found at index number : " + index); | ||
} | ||
else | ||
{ | ||
System.out.println("Not found"); | ||
} | ||
} | ||
} |
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,32 @@ | ||
import java.util.Scanner; | ||
|
||
/** | ||
* This class converts a Binary number to a Decimal number | ||
* | ||
* @author Unknown | ||
* | ||
*/ | ||
class BinaryToDecimal | ||
{ | ||
|
||
/** | ||
* Main Method | ||
* | ||
* @param args Command line arguments | ||
*/ | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
int n,k,d,s=0,c=0; | ||
n=sc.nextInt(); | ||
k=n; | ||
while(k!=0) | ||
{ | ||
d=k%10; | ||
s+=d*(int)Math.pow(2,c++); | ||
k/=10; | ||
} | ||
System.out.println("Binary number:"+n); | ||
System.out.println("Decimal equivalent:"+s); | ||
} | ||
} |
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,50 @@ | ||
import java.util.Scanner; | ||
|
||
/** | ||
* This class implements BubbleSort | ||
* | ||
* @author Unknown | ||
* | ||
*/ | ||
|
||
class BubbleSort | ||
{ | ||
/** | ||
* Main Method | ||
* | ||
* @param args Command line arguments | ||
*/ | ||
public static void main(String[] args) | ||
{ | ||
int array[]=new int[6]; | ||
Scanner input=new Scanner(System.in); | ||
|
||
//Input | ||
System.out.println("Enter any 6 Numbers for Unsorted Array : "); | ||
for(int i=0; i<6; i++) | ||
{ | ||
array[i]=input.nextInt(); | ||
} | ||
|
||
//Sorting | ||
for(int i=0; i<5; i++) | ||
{ | ||
for(int j=i+1; j<6; j++) | ||
{ | ||
if(array[j]>array[i]) | ||
{ | ||
int temp=array[j]; | ||
array[j]=array[i]; | ||
array[i]=temp; | ||
} | ||
} | ||
} | ||
|
||
//Output | ||
for(int i=0; i<6; i++) | ||
{ | ||
System.out.print(array[i]+"\t"); | ||
} | ||
|
||
} | ||
} |
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,31 @@ | ||
import java.util.Scanner; | ||
|
||
/** | ||
* This class converts a Decimal number to a Binary number | ||
* | ||
* @author Unknown | ||
* | ||
*/ | ||
class DecimalToBinary | ||
{ | ||
/** | ||
* Main Method | ||
* | ||
* @param args Command Line Arguments | ||
*/ | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
int n,k,s=0,c=0,d; | ||
n=sc.nextInt(); | ||
k=n; | ||
while(k!=0) | ||
{ | ||
d=k%2; | ||
s=s+d*(int)Math.pow(10,c++); | ||
k/=2; | ||
}//converting decimal to binary | ||
System.out.println("Decimal number:"+n); | ||
System.out.println("Binary equivalent:"+s); | ||
} | ||
} |
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,31 @@ | ||
import java.util.Scanner; | ||
|
||
/** | ||
* This class converts Decimal numbers to Octal Numbers | ||
* | ||
* @author Unknown | ||
* | ||
*/ | ||
class Decimal_Octal | ||
{ | ||
/** | ||
* Main Method | ||
* | ||
* @param args Command line Arguments | ||
*/ | ||
public static void main(String[] args) | ||
{ | ||
Scanner sc=new Scanner(System.in); | ||
int n,k,d,s=0,c=0; | ||
n=sc.nextInt(); | ||
k=n; | ||
while(k!=0) | ||
{ | ||
d=k%8; | ||
s+=d*(int)Math.pow(10,c++); | ||
k/=8; | ||
} | ||
System.out.println("Decimal number:"+n); | ||
System.out.println("Octal equivalent:"+s); | ||
} | ||
} |
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.