Skip to content
Open
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
96 changes: 96 additions & 0 deletions week-2/Java/Christopher-Fulton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@


import java.util.Scanner;



class Week2{

static void permutation(String perm,String str) {
if (str.length() == 0) { // if str is empty perm must be full permuation
System.out.println(perm + " ");
return;
}
for (int i = 0; i < str.length(); i++) {
permutation(perm+str.charAt(i), str.substring(0, i)+str.substring(i+1, str.length()));// Loop through string recursively each time add current index to substring of rest of word.
}

}



// public static String maxPalindrone(String str) {
// str = str.replaceAll("\\s",""); // replace all spaces and turn upper to lower case for simplicity
// str = str.toLowerCase();
// StringBuilder tempStr = new StringBuilder();
// StringBuilder tempBuilder = new StringBuilder();
// String maxSubstring ="";
// for(int i = 0;i<str.length();i++){
// for (int j = i+1; j<=str.length(); j++){
// tempStr.append(str.substring(i,j)); // find all substrings of str
// tempBuilder.append(tempStr.toString());// temp variable to hold object
// if(tempStr.toString().equals(tempBuilder.reverse().toString()) && tempBuilder.length() > maxSubstring.length()){
// maxSubstring = tempStr.toString();// Check wheter or not substring is a palindrone and ifso if it's largest.
// }
// tempStr.setLength(0);// Reset string objects
// tempBuilder.setLength(0);
// }
// }

// return maxSubstring;
// }
public static void main(String[] args) {
//////////////////////Interface/////////////////////////////////////////////////////
Scanner in = new Scanner(System.in);

String a = "a";
String b = "b";
System.out.println(b.compareTo(a));




















// String str = "ABC";
// for (int i = str.length()-1;i>0;i--){
// for (int j = i -1; j<str.length()-1; j++){
// System.out.println(str.substring(j, i));
// }
// }

// System.out.println("To check for Palindron enter: 1");
// System.out.println("To print all permutations 2");
// String choice = in.nextLine();
// if (choice.equals("1")) {
// System.out.println("Enter string");
// String str = in.nextLine();
// System.out.println( "Largest palidrone: ");
// System.out.println(maxPalindrone(str));
// } else if (choice.equals("2")) {
// System.out.println("Enter String ");
// String str = in.nextLine();
// System.out.println("All permutations of " + str + ":" );
// permutation("",str);

// }
// else {
// System.out.println("Incorrect choice");
// }
// in.close();
}
}
Binary file added week-2/Java/Week2.class
Binary file not shown.
Empty file removed week-2/Java/main.java
Empty file.
Binary file added week-4/Java/Week4.class
Binary file not shown.
77 changes: 77 additions & 0 deletions week-4/Java/Week4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

import java.util.*;
public class Week4{

public static int[] addElements(int num1, int num2, int carry ){ //Helper funtion to deal with carry digits
int[] sum = new int[2];
sum[0] = (num1+num2+carry)%10;
sum[1] = (num1+num2+carry)/10;
return sum;
}

public static LinkedList<Integer> sumLinkedList(LinkedList<Integer> list1, LinkedList<Integer> list2) {
LinkedList<Integer> newLinkedList = new LinkedList<Integer>();
int[] tempList1 = new int[2];
int carry = 0;

for (int i = list1.size()-1; i > -1; i--){
tempList1 = addElements(list1.get(i), list2.get(i),carry); // Holds values of array for funtion.
carry = tempList1[1];
newLinkedList.add(tempList1[0]);
}
newLinkedList.add(tempList1[1]);// BHolds
Iterator<Integer> reverseLinkIterator = newLinkedList.descendingIterator();
LinkedList<Integer> finalLinkedList = new LinkedList<Integer>();
while (reverseLinkIterator.hasNext()){
finalLinkedList.add(reverseLinkIterator.next());
}

return finalLinkedList;

}

public static LinkedList<String> rLinkedList(LinkedList<String> sLinkedList){
String[] tempArray = new String[sLinkedList.size()];
for (int i = 0; i<sLinkedList.size(); i++){
tempArray[i] = sLinkedList.get(i);
}

int tempIndex = tempArray.length;
LinkedList<String> finalLinkedList = new LinkedList<String>();
for (int i = tempArray.length-1; i > -1; i--){
if (i ==0){
for (int k = i; k<=tempIndex-1;k++)
finalLinkedList.add(tempArray[k]);
}
if (tempArray[i].equals(" ") ){
for (int j = i+1; j<=tempIndex-1;j++){
finalLinkedList.add(tempArray[j]);
}
finalLinkedList.add(" "); //Adding the space after letter.
tempIndex = i;
}
}


return finalLinkedList;
}

public static void main(String[] args) {
LinkedList<Integer> L1 = new LinkedList<Integer>();
LinkedList<Integer> L2 = new LinkedList<Integer>();
L1.add(7);
L1.add(6);
L1.add(3);
L2.add(7);
L2.add(4);
L2.add(2);
System.out.println(sumLinkedList(L1, L2)); //Only works for linked list of equal size

LinkedList<String> sLinkedList = new LinkedList<String>();
String testString = "I Love Geeks For Geeks";
for (int i =0; i <testString.length(); i++ )
sLinkedList.add(String.valueOf(testString.charAt(i)));
System.out.println(rLinkedList(sLinkedList));// Didn't test extnsively but should work for most cases.

}
}
Empty file removed week-4/Java/main.java
Empty file.
46 changes: 46 additions & 0 deletions week-6/Java/ChristopherFulton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@



class Trees{


class Node{
Node left;
Node right;
int data;

Node(int data) {
this.data = data;
left = null;
right = null;
}
}

// A Java program to introduce Binary Tree

static void getDistanceToRoot(Node node,int counter) {
if (node == null) {
counter = 0;
return;
}
counter++;

getDistanceToRoot(node.left,counter);
System.out.printf("%s ", node.data + ": " + (counter-1));
getDistanceToRoot(node.right,counter);
}

public static void main(String[] args) {
Node root = new Trees().new Node(6);
root.left =new Trees(). new Node(3);
root.right =new Trees(). new Node(8);
root.left.left =new Trees(). new Node(2);
root.left.right = new Trees(). new Node(4);
root.right.left = new Trees().new Node(1);
root.right.right =new Trees(). new Node(7);
getDistanceToRoot(root,0);
}

}


Empty file removed week-6/Java/main.java
Empty file.
67 changes: 67 additions & 0 deletions week-8/Fulton-Christopher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* IMPORTANT: Multiple classes and nested static classes are supported */

/*
* uncomment this if you want to read input.
//imports for BufferedReader
import java.io.BufferedReader;
import java.io.InputStreamReader;

//import for Scanner and other utility classes

*/

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
class Main {


static int lowestIntLinearSearch(int[] values, int k){
Map<Integer,Integer> elements = new HashMap<Integer,Integer>();
int minInt = Integer.MAX_VALUE;
for(int value: values){
if(!elements.containsKey(value))
elements.put(value,1);
else {
elements.put(value, elements.get(value) + 1);
if(value < minInt && elements.get(value) == k )
minInt = value;
}


}
return minInt;
}

static int binarySearch(int[] totals, int value){
if(totals[0] >= value)
return 1;
int start = 0;
int end = totals.length-1;
while(start <= end){
int middle = start + (end - start)/ 2;
if(totals[start] >= value)
return start + 1;

if(totals[middle] < value)
start = middle + 1;
else if(totals[middle] > value)
end = middle - 1;
}

return end;
}
public static void main(String[] args) {
int[] N = {1,2,3,4,5};
int[] totals = new int[5];
int[] queries = {3,8,10,14};
int total = 0;
for(int i = 0; i < totals.length; i++){
total+= N[i];
totals[i] = total;
}
for (int query : queries) System.out.println(binarySearch(totals, query));
int[] N2 = {2,2,1,3,1};
System.out.println(lowestIntLinearSearch(N2, 2));
}


}