Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Types of Array Sorting

Types of Array Sorting

// Selection Sort - Seleção (Performance: BAD)
public int[] selectionSort(int[] unsortedArray) {
int[] sortedArray = new int[unsortedArray.length];
for(int i = 0; i < sortedArray.length; i++) {
int minValue = sortedArray[i];
for(int k = i + 1; k < sortedArray.length; k++) {
if(sortedArray[k] < minValue) {
minValue = sortedArray[k];
}
}
sortedArray[k] = sortedArray[i];
sortedArray[i] = minValue;
}
return sortedArray;
}
// Insertion Sort - Inserção (Performance: NORMAL)
// Bubble Sort - Bolha (Performance: GOOD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment