Select sort
public class Main {
public static void main(String[] args) {
int [] arr = {9,8,7,6,5,4,3,2,1,0};
selectSort(arr);
for(int i:arr)
System.out.println(i);
}
private static void selectSort(int []arr){
for (int i=0 ; i < arr.length -1 ; i++ )
{
int min = i;
for (int j=i ; j < arr.length ; j ++)
{
if (arr[j] < arr[min])
min = j ;
}
//first find the smallest one , then swap
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp ;
}
}
}