public static void Main (string[] args) {
Int[] A = {5, 1, 10, 3, 8, 0};
for (int i = 0; i < Selectionsort (a). Length; i++) {
System.out.println (Selectionsort (a) [i]);
}
System.out.println ("-------------------------");
for (int i = 0; i < Bubblesort (a). Length; i++) {
System.out.println (Bubblesort (a) [i]);
}
System.out.println ("-------------------------");
Int[] B = {1, 6, 7, 8};
System.out.println (Bianrysearch (b, 6));
}
Select Sort (Ascending)
private static int[] Selectionsort (int[] arr) {
if (arr! = null) {
for (int i = 0; i < arr.length-1; i++) {
for (int j = i + 1; j < Arr.length; J + +) {
if (Arr[i] > Arr[j]) {
int temp = Arr[i];
Arr[i] = Arr[j];
ARR[J] = temp;
}
}
}
}
return arr;
}
Bubble sort
private static int[] Bubblesort (int[] arr) {
if (arr! = null) {
for (int i = 0; i < arr.length-1; i++) {
for (int j = 0; J < arr.length-i-1; j + +) {
if (Arr[j] < Arr[j + 1]) {
int temp = arr[j + 1];
Arr[j + 1] = Arr[j];
ARR[J] = temp;
}
}
}
}
return arr;
}
Binary lookup (the array must be ordered)
private static int Bianrysearch (int[] arr, int key) {
Starting Angle Label
int a = 0;
End Corner Mark
int b = arr.length-1;
int m = 0;
while (a <= b) {
int midx = (A + b)/2;
m = Arr[midx];
if (key > m) {
A = Midx + 1;
} else if (key < m) {
b = midx-1;
} else {
return MIDX;
}
}
return-1;
}
Java array Sorting, two-point lookup