So what I'm trying to do is to sort an array by going through the whole array and each time swap the value with the minimum value in the array. I've created a method to find minValue, but I'm not sure how to swap that value with my current value. This is probably a horrible explanation, but here's the code:
public static int findMin(int[] numList, int start, int end){
int minIndex = numList[0];
for (int i = start; i < end; i++) {
if(numList[i] < minIndex){
minIndex = numList[i];
}
}
return minIndex;
}
And my loop which is supposed to sort the array:
for (int i = 0; i < numList.length; i++) {
int minIndex = findMin(numList,i,10);
numList[i] = minIndex;
}
So as you can see, this only replaces numList[i] with the minValue. So how can I swap the value already in numList[i] with wherever in the array minValue was found?
Thanks!