Skip to content

Commit 9411d5b

Browse files
In this commit I have:
Added JavaDoc to every package except for "heaps"
1 parent 94871b7 commit 9411d5b

29 files changed

+1408
-427
lines changed

.classpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry excluding="data_structures/" kind="src" path=""/>
4+
<classpathentry kind="src" path="data_structures"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Java</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>

BinarySearch.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Implements a Binary Search in Java
5+
*
6+
* @author unknown
7+
*/
8+
class BinarySearch
9+
{
10+
/**
11+
* This method implements the Binary Search
12+
*
13+
* @param array The array to make the binary search
14+
* @param key The number you are looking for
15+
* @param lb The lower bound
16+
* @param up The upper bound
17+
* @return the location of the key
18+
**/
19+
public static int BS(int array[], int key, int lb, int ub)
20+
{ if (lb>ub)
21+
{
22+
return -1;
23+
}
24+
25+
int mid=(lb+ub)/2;
26+
27+
if (key<array[mid])
28+
{
29+
return (BS(array, key, lb, mid-1));
30+
}
31+
else if (key>array[mid])
32+
{
33+
return (BS(array, key, mid+1, ub));
34+
}
35+
else
36+
{
37+
return mid;
38+
}
39+
}
40+
41+
42+
/**
43+
* This is the main method of Binary Search
44+
*
45+
* @author Unknown
46+
* @param args Command line parameters
47+
*/
48+
49+
public static void main(String[] args)
50+
{
51+
Scanner input=new Scanner(System.in);
52+
int array[]=new int[10] ;
53+
int key;
54+
55+
//Input
56+
System.out.println("Enter an array of 10 numbers : ");
57+
for (int i=0; i<10 ;i++ )
58+
{
59+
array[i]=input.nextInt();
60+
}
61+
System.out.println("Enter the number to be searched : ");
62+
key=input.nextInt();
63+
64+
int index=BS(array, key, 0, 9);
65+
if (index!=-1)
66+
{
67+
System.out.println("Number found at index number : " + index);
68+
}
69+
else
70+
{
71+
System.out.println("Not found");
72+
}
73+
}
74+
}

BinaryToDecimal.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* This class converts a Binary number to a Decimal number
5+
*
6+
* @author Unknown
7+
*
8+
*/
9+
class BinaryToDecimal
10+
{
11+
12+
/**
13+
* Main Method
14+
*
15+
* @param args Command line arguments
16+
*/
17+
public static void main(String args[])
18+
{
19+
Scanner sc=new Scanner(System.in);
20+
int n,k,d,s=0,c=0;
21+
n=sc.nextInt();
22+
k=n;
23+
while(k!=0)
24+
{
25+
d=k%10;
26+
s+=d*(int)Math.pow(2,c++);
27+
k/=10;
28+
}
29+
System.out.println("Binary number:"+n);
30+
System.out.println("Decimal equivalent:"+s);
31+
}
32+
}

BubbleSort.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* This class implements BubbleSort
5+
*
6+
* @author Unknown
7+
*
8+
*/
9+
10+
class BubbleSort
11+
{
12+
/**
13+
* Main Method
14+
*
15+
* @param args Command line arguments
16+
*/
17+
public static void main(String[] args)
18+
{
19+
int array[]=new int[6];
20+
Scanner input=new Scanner(System.in);
21+
22+
//Input
23+
System.out.println("Enter any 6 Numbers for Unsorted Array : ");
24+
for(int i=0; i<6; i++)
25+
{
26+
array[i]=input.nextInt();
27+
}
28+
29+
//Sorting
30+
for(int i=0; i<5; i++)
31+
{
32+
for(int j=i+1; j<6; j++)
33+
{
34+
if(array[j]>array[i])
35+
{
36+
int temp=array[j];
37+
array[j]=array[i];
38+
array[i]=temp;
39+
}
40+
}
41+
}
42+
43+
//Output
44+
for(int i=0; i<6; i++)
45+
{
46+
System.out.print(array[i]+"\t");
47+
}
48+
49+
}
50+
}

DecimalToBinary.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* This class converts a Decimal number to a Binary number
5+
*
6+
* @author Unknown
7+
*
8+
*/
9+
class DecimalToBinary
10+
{
11+
/**
12+
* Main Method
13+
*
14+
* @param args Command Line Arguments
15+
*/
16+
public static void main(String args[])
17+
{
18+
Scanner sc=new Scanner(System.in);
19+
int n,k,s=0,c=0,d;
20+
n=sc.nextInt();
21+
k=n;
22+
while(k!=0)
23+
{
24+
d=k%2;
25+
s=s+d*(int)Math.pow(10,c++);
26+
k/=2;
27+
}//converting decimal to binary
28+
System.out.println("Decimal number:"+n);
29+
System.out.println("Binary equivalent:"+s);
30+
}
31+
}

DecimalToOctal.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* This class converts Decimal numbers to Octal Numbers
5+
*
6+
* @author Unknown
7+
*
8+
*/
9+
class Decimal_Octal
10+
{
11+
/**
12+
* Main Method
13+
*
14+
* @param args Command line Arguments
15+
*/
16+
public static void main(String[] args)
17+
{
18+
Scanner sc=new Scanner(System.in);
19+
int n,k,d,s=0,c=0;
20+
n=sc.nextInt();
21+
k=n;
22+
while(k!=0)
23+
{
24+
d=k%8;
25+
s+=d*(int)Math.pow(10,c++);
26+
k/=8;
27+
}
28+
System.out.println("Decimal number:"+n);
29+
System.out.println("Octal equivalent:"+s);
30+
}
31+
}

Factorial.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import java.util.Scanner;
22

3+
/**
4+
* This program will print out the factorial of any non-negative
5+
* number that you input into it.
6+
*
7+
* @author Unknown
8+
*
9+
*/
310
public class Factorial{
411

12+
/**
13+
* The main method
14+
*
15+
* @param args Command line arguments
16+
*/
517
public static void main(String[] args){
618
Scanner input = new Scanner(System.in);
719
//Prompt user to enter integer
@@ -20,7 +32,12 @@ public static void main(String[] args){
2032
}
2133
}
2234

23-
//Factorial method
35+
/**
36+
* Recursive Factorial Method
37+
*
38+
* @param n The number to factorial
39+
* @return The factorial of the number
40+
*/
2441
public static long factorial(int n){
2542

2643
if (n==0){

FindingPrimes.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
/*
2-
* The Sieve of Eratosthenes is an algorithm used to find prime numbers, up to a given value.
1+
/**
2+
* The Sieve of Eratosthenes is an algorithm use to find prime numbers,
3+
* up to a given value.
34
* Illustration: https://upload.wikimedia.org/wikipedia/commons/b/b9/Sieve_of_Eratosthenes_animation.gif
4-
*/
5+
* (This illustration is also in the github repository)
6+
*
7+
* @author Unknown
8+
*
9+
*/
510
public class FindingPrimes{
11+
/**
12+
* The Main method
13+
*
14+
* @param args Command line arguments
15+
*/
616
public static void main(String args[]){
717
SOE(20); //Example: Finds all the primes up to 20
818
}
919

20+
/**
21+
* The method implementing the Sieve of Eratosthenes
22+
*
23+
* @param n Number to perform SOE on
24+
*/
1025
public static void SOE(int n){
1126
boolean sieve[] = new boolean[n];
1227

0 commit comments

Comments
 (0)