- Closed all Scanner and Buffered Readers

- Added Some Java Doc

- ReverseString - took space out of between each letter so "Zachary" to
"yrahcaZ" instead of "y r a h c aZ"

- bfs - Trying to repair this class but need to research bfs more

- dfs - Trying to repair this class but need to research dfs more

- Added new Classes
1) OctalToBinary - Not done
2) BinaryToOctal - Not done
3) OctalToDecimal - Not done
4) Graphs

-Added the dataStructure Graphs (Unfinished)
This commit is contained in:
zacharyjones123
2017-04-20 11:56:21 -07:00
parent abbc4bee08
commit 03dbfa78c8
21 changed files with 179 additions and 24 deletions

View File

@ -70,5 +70,6 @@ class BinarySearch
{
System.out.println("Not found");
}
input.close();
}
}

View File

@ -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();
}
}

35
BinaryToOctal.java Normal file
View File

@ -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) {
}
}

View File

@ -45,6 +45,6 @@ class BubbleSort
{
System.out.print(array[i]+"\t");
}
input.close();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -30,6 +30,7 @@ public class Factorial{
System.out.println("The factorial of "+number+" will yield: "+factorial(number));
}
}
input.close();
}
/**

View File

@ -44,6 +44,6 @@ class InsertionSort
{
System.out.print(array[i]+"\t");
}
input.close();
}
}

View File

@ -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];

View File

@ -28,6 +28,7 @@ public class LinearSearch{
printarray(myArray);
System.out.printf("The integer %d is found in index %d\n", key, linearsearch(myArray, key));
input.close();
}
/**

34
OctalToBinary.java Normal file
View File

@ -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) {
}
}

34
OctalToDecimal.java Normal file
View File

@ -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) {
}
}

View File

@ -38,6 +38,8 @@ public class Quicksort{
System.out.println("The sorted array is: ");
printarray(array);
System.out.println();
input.close();
}
/**

View File

@ -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();
}
}

View File

@ -48,5 +48,6 @@ class SelectionSort
System.out.print(array[i]+"\t");
}
input.close();
}
}

View File

@ -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 <Integer> 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<vertices;i++){
if(a[pop][i]!=0 && b[i]!=(byte)0 && b[i]!=(byte)1 ){
st.add(i);
st.push(i);
b[i]=(byte)0; //assigning waiting status
}}}
}
@ -56,5 +56,7 @@ public class bfs{
a[i][in.nextInt()]=1; //taking adjacency entries by assigning 1
}
}
bfs(a,vertices,source); //function call
}}
bfsImplement(a,vertices,source); //function call
in.close();
}
}

View File

@ -28,5 +28,6 @@ class CountTheWords
}
}
System.out.println("Number of words in the string = "+count);
sc.close();
}
}

View File

@ -0,0 +1,32 @@
/**
* This class implements the Graph data structure
* using the classes Graph and Graphs.
*
* @author Zachary Jones
*
*/
class Graph {
}
/**
* This class is used to test the Graph
* class above.
*
* @author Zachary Jones
*
*/
public class Graphs {
/**
* Main method
*
* @param args Command line arguments
*/
public static void main(String args[]) {
}
}

View File

@ -88,7 +88,6 @@ public class MaxHeap 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 > maxHeap.size()) && (elementIndex <= 0)) throw new IndexOutOfBoundsException("Index out of heap range");

View File

@ -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");

View File

@ -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 <Integer> 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();
}
}