public class Array {
public static void sort(int[] list) {
int min;
int temp;
for(int i = 0; i < list.length - 1; i++) {
min = i;
for(int j = i + 1; j < list.length; j++) {
if(list[j] < list[min]){
min = j;
}
}
temp = list[min];
list[min] = list[i];
list[i] = temp;
}
}
public static void main(String[] args) {
int a[] = {2,1,3};
sort(a);
for(int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
I understand everything in this program until I get to:
temp = list[min];
list[min] = list[i];
list[i] = temp;
Can someone explain this in in simple terms? In other words, what is the purpose of the above?