Created
June 29, 2012 22:18
-
-
Save sumtyme/3021013 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExtremaTests { | |
// maxArray() | |
// returns the largest value in int array A | |
static int maxArray(int[] A, int start, int end) { | |
if (start < end) { | |
int middle = (start + end) / 2; | |
maxArray(A, start, middle); | |
maxArray(A, middle + 1, end); | |
return Math.max(maxArray(A, start, middle), maxArray(A, middle + 1, end)); | |
}else{ | |
return A[start]; | |
} | |
} | |
public static void main(String[] args) { | |
int[] B = {111, 222}; | |
System.out.println("max = " + maxArray(B, 0, B.length - 1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment