Last active
July 13, 2017 19:16
-
-
Save alexleventer/f833e493d97c92ee0fe79e40dc0d57d6 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
public class BinarySearch | |
{ | |
public static int binarySearch(int[] a, int target) | |
{ | |
int left = 0, right = a.length -1; | |
while (left <= right) | |
{ | |
int mid = (left + right) / 2; | |
if(a[mid] == target) | |
return mid; | |
else if (a[mid] < target) | |
left = mid + 1; | |
else | |
right = mid -1; | |
} | |
return -1; | |
} | |
public static void main(String[] args) | |
{ | |
} | |
} |
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
public class SelectionSort | |
{ | |
public static int[] selectionSort(int[] a) | |
{ | |
int temp, min; | |
for (int i = 0; i < a.length - 1; i++) | |
{ | |
min = i; | |
for (int j = i + 1; j < a.length; i++) | |
{ | |
if (a[j] < a[min]) | |
min = j | |
} | |
if (min != i) | |
{ | |
temp = a[i]; | |
a[i] = a[min]; | |
a[min] = temp; | |
} | |
} | |
} | |
public static void main(String[] args) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment