Skip to content

Instantly share code, notes, and snippets.

@diogocapela
Last active December 18, 2017 16:11
Show Gist options
  • Save diogocapela/7a407a81ec90ba44a6e8566428e64756 to your computer and use it in GitHub Desktop.
Save diogocapela/7a407a81ec90ba44a6e8566428e64756 to your computer and use it in GitHub Desktop.
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