Skip to content

More Additions (Info below) #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BinarySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ public static void main(String[] args)
{
System.out.println("Not found");
}
input.close();
}
}
3 changes: 2 additions & 1 deletion BinaryToDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static void main(String args[])
{
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)
Expand All @@ -26,7 +27,7 @@ public static void main(String args[])
s+=d*(int)Math.pow(2,c++);
k/=10;
}
System.out.println("Binary number:"+n);
System.out.println("Decimal equivalent:"+s);
sc.close();
}
}
35 changes: 35 additions & 0 deletions BinaryToOctal.java
Original file line number Diff line number Diff line change
@@ -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) {

}

}
2 changes: 1 addition & 1 deletion BubbleSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public static void main(String[] args)
{
System.out.print(array[i]+"\t");
}

input.close();
}
}
3 changes: 2 additions & 1 deletion DecimalToBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void main(String args[])
{
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)
Expand All @@ -25,7 +26,7 @@ public static void main(String args[])
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();
}
}
4 changes: 3 additions & 1 deletion DecimalToOctal.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void main(String[] args)
{
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)
Expand All @@ -25,7 +26,8 @@ public static void main(String[] args)
s+=d*(int)Math.pow(10,c++);
k/=8;
}
System.out.println("Decimal number:"+n);

System.out.println("Octal equivalent:"+s);
sc.close();
}
}
3 changes: 2 additions & 1 deletion Factorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static void main(String[] args){
//Output of factorial for any non-negative number
System.out.println("The factorial of "+number+" will yield: "+factorial(number));
}
}
}
input.close();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion InsertionSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public static void main(String[] args)
{
System.out.print(array[i]+"\t");
}

input.close();
}
}
6 changes: 6 additions & 0 deletions InsertionSortInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion LinearSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static void main(String[] args){
//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();
}

/**
Expand Down
34 changes: 34 additions & 0 deletions OctalToBinary.java
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions OctalToDecimal.java
Original file line number Diff line number Diff line change
@@ -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) {

}

}
2 changes: 2 additions & 0 deletions Quicksort.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static void main(String[] args){
System.out.println("The sorted array is: ");
printarray(array);
System.out.println();

input.close();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion ReverseString.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ReverseString
*/
static String reverseString(String str)
{
String reverse=" ";
String reverse="";
if(str.length()==1)
{
return str;
Expand All @@ -42,6 +42,7 @@ public static void main(String args[]) throws IOException
System.out.println("Enter the string");
String srr=br.readLine();
System.out.println("Reverse="+reverseString(srr));
br.close();
}
}

3 changes: 2 additions & 1 deletion SelectionSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void main(String[] args)
{
System.out.print(array[i]+"\t");
}


input.close();
}
}
20 changes: 11 additions & 9 deletions bfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ 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
-1 = ready
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
}}}
}
Expand All @@ -56,5 +56,7 @@ public static void main(String args[]){
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();
}
}
1 change: 1 addition & 0 deletions countwords.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public static void main(String args[])
}
}
System.out.println("Number of words in the string = "+count);
sc.close();
}
}
42 changes: 42 additions & 0 deletions data_structures/CircleLinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
public class CircleLinkedList<E>{
private static class Node<E>{
Node<E> next;
E value;
private Node(E value, Node<E> next){
this.value = value;
this.next = next;
}
}
private int size; //For better O.O design this should be private allows for better black box design
private Node<E> head; //this will point to dummy node;
public CircleLinkedList(){ //constructer for class.. here we will make a dummy node for circly linked list implementation with reduced error catching as our list will never be empty;
head = new Node<E>(null,head); //creation of the dummy node
size = 0;
}
public int getSize(){ return size;} // getter for the size... needed because size is private.
public void append(E value){ // for the sake of simplistiy this class will only contain the append function or addLast other add functions can be implemented however this is the basses of them all really.
if(value == null){
throw new NullPointerException("Cannot add null element to the list"); // we do not want to add null elements to the list.
}
head.next = new Node<E>(value,head); //head.next points to the last element;
size++;}
public E remove(int pos){
if(pos>size || pos< 0){
throw new IndexOutOfBoundsException("position cannot be greater than size or negative"); //catching errors
}
Node<E> iterator = head.next;
Node<E> before = head; //we need to keep track of the element before the element we want to remove we can see why bellow.
for(int i = 1; i<=pos; i++){
iterator = iterator.next;
before = before.next;
}
E saved = iterator.value;
before.next = iterator.next; // assigning the next referance to the the element following the element we want to remove... the last element will be assigned to the head.
iterator.next = null; // scrubbing
iterator.value = null;
return saved;

}

}

32 changes: 32 additions & 0 deletions data_structures/Graphs.java
Original file line number Diff line number Diff line change
@@ -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[]) {

}

}
1 change: 0 additions & 1 deletion data_structures/heaps/MaxHeap.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void deleteElement(int elementIndex) {
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");
Expand Down
1 change: 0 additions & 1 deletion data_structures/heaps/MinHeap.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public void deleteElement(int elementIndex) {
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");
Expand Down
Loading