I apologize if my question angers anyone since there is a few Selection Sort related questions already out here in Stack Overflow, but I have looked at nearly all of them, and still find myself confused.
I'm simply trying to write a Selection Sort in the correct format. However, I found many people were using two IF statements in them, while others did not.
What I need to know is if Selection Sorts require two IF Statements, or is the way I have written it acceptable?
What I ended up writing so far was this:
public static int[] selectionsort(int[] anArray){
int temp;
for(int i = 0; i < anArray.length; i++){
for(int leastIndex = i + 1; leastIndex < anArray.length; leastIndex++){
if(anArray[i] > anArray[leastIndex]){
temp = anArray[i];
anArray[i] = anArray[leastIndex];
anArray[leastIndex] = temp;
}
}
}
return anArray;
}
The program does run, but I need to make sure that I have written the Selection Sort correctly.