Last active
December 18, 2017 16:11
-
-
Save diogocapela/7a407a81ec90ba44a6e8566428e64756 to your computer and use it in GitHub Desktop.
Types of Array Sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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