Skip to content

Commit ca4305a

Browse files
Merge pull request #27 from zacharyjones123/master
More Additions (Info below)
2 parents a030efd + 03dbfa7 commit ca4305a

21 files changed

+179
-24
lines changed

BinarySearch.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ public static void main(String[] args)
7070
{
7171
System.out.println("Not found");
7272
}
73+
input.close();
7374
}
7475
}

BinaryToDecimal.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static void main(String args[])
1818
{
1919
Scanner sc=new Scanner(System.in);
2020
int n,k,d,s=0,c=0;
21+
System.out.print("Binary number: ");
2122
n=sc.nextInt();
2223
k=n;
2324
while(k!=0)
@@ -26,7 +27,7 @@ public static void main(String args[])
2627
s+=d*(int)Math.pow(2,c++);
2728
k/=10;
2829
}
29-
System.out.println("Binary number:"+n);
3030
System.out.println("Decimal equivalent:"+s);
31+
sc.close();
3132
}
3233
}

BinaryToOctal.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Converts any Binary number to an Octal Number
5+
*
6+
* @author Zachary Jones
7+
*
8+
*/
9+
public class BinaryToOctal {
10+
11+
/**
12+
* Main method
13+
*
14+
* @param args Command line arguments
15+
*/
16+
public static void main(String args[]) {
17+
Scanner sc = new Scanner(System.in);
18+
int b = sc.nextInt();
19+
System.out.println("Octal equivalent: " + convertBinaryToOctal(b));
20+
sc.close();
21+
22+
}
23+
24+
/**
25+
* This method converts a binary number to
26+
* an octal number.
27+
*
28+
* @param b The binary number
29+
* @return The octal number
30+
*/
31+
public static int convertBinaryToOctal(int b) {
32+
33+
}
34+
35+
}

BubbleSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public static void main(String[] args)
4545
{
4646
System.out.print(array[i]+"\t");
4747
}
48-
48+
input.close();
4949
}
5050
}

DecimalToBinary.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static void main(String args[])
1717
{
1818
Scanner sc=new Scanner(System.in);
1919
int n,k,s=0,c=0,d;
20+
System.out.print("Decimal number: ");
2021
n=sc.nextInt();
2122
k=n;
2223
while(k!=0)
@@ -25,7 +26,7 @@ public static void main(String args[])
2526
s=s+d*(int)Math.pow(10,c++);
2627
k/=2;
2728
}//converting decimal to binary
28-
System.out.println("Decimal number:"+n);
2929
System.out.println("Binary equivalent:"+s);
30+
sc.close();
3031
}
3132
}

DecimalToOctal.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static void main(String[] args)
1717
{
1818
Scanner sc=new Scanner(System.in);
1919
int n,k,d,s=0,c=0;
20+
System.out.print("Decimal number: ");
2021
n=sc.nextInt();
2122
k=n;
2223
while(k!=0)
@@ -25,7 +26,8 @@ public static void main(String[] args)
2526
s+=d*(int)Math.pow(10,c++);
2627
k/=8;
2728
}
28-
System.out.println("Decimal number:"+n);
29+
2930
System.out.println("Octal equivalent:"+s);
31+
sc.close();
3032
}
3133
}

Factorial.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static void main(String[] args){
2929
//Output of factorial for any non-negative number
3030
System.out.println("The factorial of "+number+" will yield: "+factorial(number));
3131
}
32-
}
32+
}
33+
input.close();
3334
}
3435

3536
/**

InsertionSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public static void main(String[] args)
4444
{
4545
System.out.print(array[i]+"\t");
4646
}
47-
47+
input.close();
4848
}
4949
}

InsertionSortInteger.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
public class InsertionSortInteger {
1212

1313

14+
/**
15+
* This method implements insertion sort by integer
16+
*
17+
* @param initialArray array to be sorted
18+
* @return sorted array
19+
*/
1420
public int[] insertionIntArraySort(int[] initialArray){
1521

1622
int[] sortedArray = new int[initialArray.length];

LinearSearch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static void main(String[] args){
2727
//Output array and index of target element, if found
2828
printarray(myArray);
2929
System.out.printf("The integer %d is found in index %d\n", key, linearsearch(myArray, key));
30-
30+
31+
input.close();
3132
}
3233

3334
/**

OctalToBinary.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Converts any Octal number to a Binary number
5+
*
6+
* @author Zachary Jones
7+
*
8+
*/
9+
public class OctalToBinary {
10+
11+
/**
12+
* Main method
13+
*
14+
* @param args Command line arguments
15+
*/
16+
public static void main(String args[]) {
17+
Scanner sc = new Scanner(System.in);
18+
int o = sc.nextInt();
19+
System.out.println("Binary equivalent: " + convertOctalToBinary(o));
20+
sc.close();
21+
}
22+
23+
/**
24+
* This method converts an octal number
25+
* to a binary number.
26+
*
27+
* @param o The octal number
28+
* @return The binary number
29+
*/
30+
public static int convertOctalToBinary(int o) {
31+
32+
}
33+
34+
}

OctalToDecimal.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Converts any Octal Number to a Decimal Number
5+
*
6+
* @author Zachary Jones
7+
*
8+
*/
9+
public class OctalToDecimal {
10+
11+
/**
12+
* Main method
13+
*
14+
* @param args Command line arguments
15+
*/
16+
public static void main(String args[]) {
17+
Scanner sc = new Scanner(System.in);
18+
int o = sc.nextInt();
19+
System.out.println("Decimal equivalent: " + convertOctalToDecimal(o));
20+
sc.close();
21+
}
22+
23+
/**
24+
* This method converts an octal number to
25+
* a decimal number.
26+
*
27+
* @param o The octal number
28+
* @return The decimal number
29+
*/
30+
public static int convertOctalToDecimal(int o) {
31+
32+
}
33+
34+
}

Quicksort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public static void main(String[] args){
3838
System.out.println("The sorted array is: ");
3939
printarray(array);
4040
System.out.println();
41+
42+
input.close();
4143
}
4244

4345
/**

ReverseString.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ReverseString
1818
*/
1919
static String reverseString(String str)
2020
{
21-
String reverse=" ";
21+
String reverse="";
2222
if(str.length()==1)
2323
{
2424
return str;
@@ -42,6 +42,7 @@ public static void main(String args[]) throws IOException
4242
System.out.println("Enter the string");
4343
String srr=br.readLine();
4444
System.out.println("Reverse="+reverseString(srr));
45+
br.close();
4546
}
4647
}
4748

SelectionSort.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void main(String[] args)
4747
{
4848
System.out.print(array[i]+"\t");
4949
}
50-
50+
51+
input.close();
5152
}
5253
}

bfs.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ public class bfs{
1515
* @param vertices The vertices to use
1616
* @param source The Source
1717
*/
18-
public static void bfs(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices
18+
public static void bfsImplement(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices
1919
byte []b=new byte[vertices]; //flag container containing status of each vertices
2020
Arrays.fill(b,(byte)-1); //status initialization
2121
/* code status
2222
-1 = ready
2323
0 = waiting
2424
1 = processed */
2525

26-
Queue <Integer> st=new Queue<>(); //operational stack
27-
st.add(source); //assigning source
26+
Stack st = new Stack(vertices); //operational stack
27+
st.push(source); //assigning source
2828
while(!st.isEmpty()){
2929
b[st.peek()]=(byte)0; //assigning waiting status
30-
System.out.println(st.element());
31-
int pop=st.element();
30+
System.out.println(st.peek());
31+
int pop=st.peek();
3232
b[pop]=(byte)1; //assigning processed status
33-
st.remove(); //removing head of the queue
33+
st.pop(); //removing head of the queue
3434
for(int i=0;i<vertices;i++){
3535
if(a[pop][i]!=0 && b[i]!=(byte)0 && b[i]!=(byte)1 ){
36-
st.add(i);
36+
st.push(i);
3737
b[i]=(byte)0; //assigning waiting status
3838
}}}
3939
}
@@ -56,5 +56,7 @@ public static void main(String args[]){
5656
a[i][in.nextInt()]=1; //taking adjacency entries by assigning 1
5757
}
5858
}
59-
bfs(a,vertices,source); //function call
60-
}}
59+
bfsImplement(a,vertices,source); //function call
60+
in.close();
61+
}
62+
}

countwords.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ public static void main(String args[])
2828
}
2929
}
3030
System.out.println("Number of words in the string = "+count);
31+
sc.close();
3132
}
3233
}

data_structures/Graphs.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
/**
3+
* This class implements the Graph data structure
4+
* using the classes Graph and Graphs.
5+
*
6+
* @author Zachary Jones
7+
*
8+
*/
9+
class Graph {
10+
11+
}
12+
13+
/**
14+
* This class is used to test the Graph
15+
* class above.
16+
*
17+
* @author Zachary Jones
18+
*
19+
*/
20+
21+
public class Graphs {
22+
23+
/**
24+
* Main method
25+
*
26+
* @param args Command line arguments
27+
*/
28+
public static void main(String args[]) {
29+
30+
}
31+
32+
}

data_structures/heaps/MaxHeap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public void deleteElement(int elementIndex) {
8888
try {
8989
throw new EmptyHeapException("Attempt to delete an element from an empty heap");
9090
} catch (EmptyHeapException e) {
91-
// TODO Auto-generated catch block
9291
e.printStackTrace();
9392
}
9493
if ((elementIndex > maxHeap.size()) && (elementIndex <= 0)) throw new IndexOutOfBoundsException("Index out of heap range");

data_structures/heaps/MinHeap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public void deleteElement(int elementIndex) {
9191
try {
9292
throw new EmptyHeapException("Attempt to delete an element from an empty heap");
9393
} catch (EmptyHeapException e) {
94-
// TODO Auto-generated catch block
9594
e.printStackTrace();
9695
}
9796
if ((elementIndex > minHeap.size()) && (elementIndex <= 0)) throw new IndexOutOfBoundsException("Index out of heap range");

dfs.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class dfs{
1616
* @param vertices The vertices
1717
* @param source The source
1818
*/
19-
public static void dfs(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices
19+
public static void dfsImplement(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices
2020
byte []b=new byte[vertices]; //flag container containing status of each vertices
2121
Arrays.fill(b,(byte)-1); //status initialization
2222
/* code status
@@ -25,7 +25,7 @@ public static void dfs(byte [][] a,int vertices,int source){ //passin
2525
1 = processed */
2626

2727

28-
Stack <Integer> st=new Stack<>(); //operational stack
28+
Stack st=new Stack(vertices); //operational stack
2929
st.push(source); //assigning source
3030
while(!st.isEmpty()){
3131
b[st.peek()]=(byte)0; //assigning waiting status
@@ -57,5 +57,7 @@ public static void main(String args[]){
5757
a[i][in.nextInt()]=1; //taking adjacency entries by assigning 1
5858
}
5959
}
60-
bfs(a,vertices,source); //function call
61-
}}
60+
dfsImplement(a,vertices,source); //function call
61+
in.close();
62+
}
63+
}

0 commit comments

Comments
 (0)