diff --git a/BinarySearch.java b/BinarySearch.java index 25814197f..54f2c4c81 100644 --- a/BinarySearch.java +++ b/BinarySearch.java @@ -70,5 +70,6 @@ class BinarySearch { System.out.println("Not found"); } + input.close(); } } diff --git a/BinaryToDecimal.java b/BinaryToDecimal.java index f7357d3ce..9e5494eeb 100644 --- a/BinaryToDecimal.java +++ b/BinaryToDecimal.java @@ -18,6 +18,7 @@ class BinaryToDecimal { Scanner sc=new Scanner(System.in); int n,k,d,s=0,c=0; + System.out.print("Binary number: "); n=sc.nextInt(); k=n; while(k!=0) @@ -26,7 +27,7 @@ class BinaryToDecimal s+=d*(int)Math.pow(2,c++); k/=10; } - System.out.println("Binary number:"+n); System.out.println("Decimal equivalent:"+s); + sc.close(); } } diff --git a/BinaryToOctal.java b/BinaryToOctal.java new file mode 100644 index 000000000..1e2dcd818 --- /dev/null +++ b/BinaryToOctal.java @@ -0,0 +1,35 @@ +import java.util.Scanner; + +/** + * Converts any Binary number to an Octal Number + * + * @author Zachary Jones + * + */ +public class BinaryToOctal { + + /** + * Main method + * + * @param args Command line arguments + */ + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + int b = sc.nextInt(); + System.out.println("Octal equivalent: " + convertBinaryToOctal(b)); + sc.close(); + + } + + /** + * This method converts a binary number to + * an octal number. + * + * @param b The binary number + * @return The octal number + */ + public static int convertBinaryToOctal(int b) { + + } + +} diff --git a/BubbleSort.java b/BubbleSort.java index ac4015f18..7e7c72f6a 100644 --- a/BubbleSort.java +++ b/BubbleSort.java @@ -45,6 +45,6 @@ class BubbleSort { System.out.print(array[i]+"\t"); } - + input.close(); } } diff --git a/DecimalToBinary.java b/DecimalToBinary.java index e88c7d976..671cedf20 100644 --- a/DecimalToBinary.java +++ b/DecimalToBinary.java @@ -17,6 +17,7 @@ class DecimalToBinary { Scanner sc=new Scanner(System.in); int n,k,s=0,c=0,d; + System.out.print("Decimal number: "); n=sc.nextInt(); k=n; while(k!=0) @@ -25,7 +26,7 @@ class DecimalToBinary 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); + sc.close(); } } diff --git a/DecimalToOctal.java b/DecimalToOctal.java index f05903160..1efa00f8b 100644 --- a/DecimalToOctal.java +++ b/DecimalToOctal.java @@ -17,6 +17,7 @@ class Decimal_Octal { Scanner sc=new Scanner(System.in); int n,k,d,s=0,c=0; + System.out.print("Decimal number: "); n=sc.nextInt(); k=n; while(k!=0) @@ -25,7 +26,8 @@ class Decimal_Octal s+=d*(int)Math.pow(10,c++); k/=8; } - System.out.println("Decimal number:"+n); + System.out.println("Octal equivalent:"+s); + sc.close(); } } diff --git a/Factorial.java b/Factorial.java index 134ec2f5d..a3b4052ed 100644 --- a/Factorial.java +++ b/Factorial.java @@ -29,7 +29,8 @@ public class Factorial{ //Output of factorial for any non-negative number System.out.println("The factorial of "+number+" will yield: "+factorial(number)); } - } + } + input.close(); } /** diff --git a/InsertionSort.java b/InsertionSort.java index 772b5a77e..0fa34c2b4 100644 --- a/InsertionSort.java +++ b/InsertionSort.java @@ -44,6 +44,6 @@ class InsertionSort { System.out.print(array[i]+"\t"); } - + input.close(); } } \ No newline at end of file diff --git a/InsertionSortInteger.java b/InsertionSortInteger.java index 7f4cfce29..fa31ac256 100644 --- a/InsertionSortInteger.java +++ b/InsertionSortInteger.java @@ -11,6 +11,12 @@ public class InsertionSortInteger { + /** + * This method implements insertion sort by integer + * + * @param initialArray array to be sorted + * @return sorted array + */ public int[] insertionIntArraySort(int[] initialArray){ int[] sortedArray = new int[initialArray.length]; diff --git a/LinearSearch.java b/LinearSearch.java index f74f4ad09..cac1d4995 100644 --- a/LinearSearch.java +++ b/LinearSearch.java @@ -27,7 +27,8 @@ public class LinearSearch{ //Output array and index of target element, if found printarray(myArray); System.out.printf("The integer %d is found in index %d\n", key, linearsearch(myArray, key)); - + + input.close(); } /** diff --git a/OctalToBinary.java b/OctalToBinary.java new file mode 100644 index 000000000..23c9a46ad --- /dev/null +++ b/OctalToBinary.java @@ -0,0 +1,34 @@ +import java.util.Scanner; + +/** + * Converts any Octal number to a Binary number + * + * @author Zachary Jones + * + */ +public class OctalToBinary { + + /** + * Main method + * + * @param args Command line arguments + */ + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + int o = sc.nextInt(); + System.out.println("Binary equivalent: " + convertOctalToBinary(o)); + sc.close(); + } + + /** + * This method converts an octal number + * to a binary number. + * + * @param o The octal number + * @return The binary number + */ + public static int convertOctalToBinary(int o) { + + } + +} diff --git a/OctalToDecimal.java b/OctalToDecimal.java new file mode 100644 index 000000000..fe82b5fff --- /dev/null +++ b/OctalToDecimal.java @@ -0,0 +1,34 @@ +import java.util.Scanner; + +/** + * Converts any Octal Number to a Decimal Number + * + * @author Zachary Jones + * + */ +public class OctalToDecimal { + + /** + * Main method + * + * @param args Command line arguments + */ + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + int o = sc.nextInt(); + System.out.println("Decimal equivalent: " + convertOctalToDecimal(o)); + sc.close(); + } + + /** + * This method converts an octal number to + * a decimal number. + * + * @param o The octal number + * @return The decimal number + */ + public static int convertOctalToDecimal(int o) { + + } + +} diff --git a/Quicksort.java b/Quicksort.java index 5b5896f8a..886f0e772 100644 --- a/Quicksort.java +++ b/Quicksort.java @@ -38,6 +38,8 @@ public class Quicksort{ System.out.println("The sorted array is: "); printarray(array); System.out.println(); + + input.close(); } /** diff --git a/ReverseString.java b/ReverseString.java index e8a75b3ed..409735502 100644 --- a/ReverseString.java +++ b/ReverseString.java @@ -18,7 +18,7 @@ class ReverseString */ static String reverseString(String str) { - String reverse=" "; + String reverse=""; if(str.length()==1) { return str; @@ -42,6 +42,7 @@ class ReverseString System.out.println("Enter the string"); String srr=br.readLine(); System.out.println("Reverse="+reverseString(srr)); + br.close(); } } \ No newline at end of file diff --git a/SelectionSort.java b/SelectionSort.java index d8e1e0032..82fecda12 100644 --- a/SelectionSort.java +++ b/SelectionSort.java @@ -47,6 +47,7 @@ class SelectionSort { System.out.print(array[i]+"\t"); } - + + input.close(); } } \ No newline at end of file diff --git a/bfs.java b/bfs.java index 085e302cc..90ff4eca8 100644 --- a/bfs.java +++ b/bfs.java @@ -15,7 +15,7 @@ public class bfs{ * @param vertices The vertices to use * @param source The Source */ - public static void bfs(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices + public static void bfsImplement(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices byte []b=new byte[vertices]; //flag container containing status of each vertices Arrays.fill(b,(byte)-1); //status initialization /* code status @@ -23,17 +23,17 @@ public class bfs{ 0 = waiting 1 = processed */ - Queue st=new Queue<>(); //operational stack - st.add(source); //assigning source + Stack st = new Stack(vertices); //operational stack + st.push(source); //assigning source while(!st.isEmpty()){ b[st.peek()]=(byte)0; //assigning waiting status - System.out.println(st.element()); - int pop=st.element(); + System.out.println(st.peek()); + int pop=st.peek(); b[pop]=(byte)1; //assigning processed status - st.remove(); //removing head of the queue + st.pop(); //removing head of the queue for(int i=0;i maxHeap.size()) && (elementIndex <= 0)) throw new IndexOutOfBoundsException("Index out of heap range"); diff --git a/data_structures/heaps/MinHeap.java b/data_structures/heaps/MinHeap.java index 5793bb92f..fbf2b86ff 100644 --- a/data_structures/heaps/MinHeap.java +++ b/data_structures/heaps/MinHeap.java @@ -91,7 +91,6 @@ public class MinHeap implements Heap { try { throw new EmptyHeapException("Attempt to delete an element from an empty heap"); } catch (EmptyHeapException e) { - // TODO Auto-generated catch block e.printStackTrace(); } if ((elementIndex > minHeap.size()) && (elementIndex <= 0)) throw new IndexOutOfBoundsException("Index out of heap range"); diff --git a/dfs.java b/dfs.java index 023e1d5ff..8ceba166e 100644 --- a/dfs.java +++ b/dfs.java @@ -16,7 +16,7 @@ public class dfs{ * @param vertices The vertices * @param source The source */ - public static void dfs(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices + public static void dfsImplement(byte [][] a,int vertices,int source){ //passing adjacency matrix and no of vertices byte []b=new byte[vertices]; //flag container containing status of each vertices Arrays.fill(b,(byte)-1); //status initialization /* code status @@ -25,7 +25,7 @@ public class dfs{ 1 = processed */ - Stack st=new Stack<>(); //operational stack + Stack st=new Stack(vertices); //operational stack st.push(source); //assigning source while(!st.isEmpty()){ b[st.peek()]=(byte)0; //assigning waiting status @@ -57,5 +57,7 @@ public class dfs{ a[i][in.nextInt()]=1; //taking adjacency entries by assigning 1 } } - bfs(a,vertices,source); //function call - }} + dfsImplement(a,vertices,source); //function call + in.close(); + } +}