Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Created November 13, 2018 14:13
Show Gist options
  • Save XcqRomance/894a656e2685dc20c47c93d2631a5874 to your computer and use it in GitHub Desktop.
Save XcqRomance/894a656e2685dc20c47c93d2631a5874 to your computer and use it in GitHub Desktop.
选择排序 时间复杂度:O(n^2) 空间复杂度:O(1) 不稳定排序:排序算法的稳定性:通俗地讲就是能保证排序前两个相等的数据其在序列中的先后位置顺序与排序后它们两个先后位置顺序相同。
// 选择排序 找到最小元素的角标位置
void selectionSort(int *arr,int arrSize) {
for (int i = 0 ; i < arrSize; i ++) {
int minIndex = i;
for (int j = i+1; j < arrSize; j++) {
if (arr[j]<arr[minIndex]) {
minIndex = j;
}
}
swap(arr, i, minIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment