Select Sort
public
class ArrayDemoSelectSort {
private void printArr(int[] arr1) {
// TODO Auto-generated method stub
for (int obj : arr1) {
System.out.print(obj);
}
}
private void sortArr(int[] arr) {
// TODO Auto-generated method stub
for (int x = 0; x < arr.length - 1; x++) {
for (int y = x + 1; y < arr.length; y++) {
if (arr[x] > arr[y]) {
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
}
}
}
public static void main(String[] args) {
ArrayDemoSelectSort Arr = new ArrayDemoSelectSort();
int[] arr1 = new int[] { 1, 3, 2, 8, 5 };
Arr.sortArr(arr1);
Arr.printArr(arr1);
}
}