Created
November 13, 2018 12:45
-
-
Save XcqRomance/30c7e0a842f19062deb141274a2c3f6c to your computer and use it in GitHub Desktop.
冒泡排序 时间复杂度:O(n^2) 空间复杂度:O(1),原地排序 稳定排序
This file contains 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
// 冒泡排序 反复交换相邻的未按照次序排列元素 | |
// 一组数中,相邻的两个数进行比较、交换,将最大(小)数交换至尾(首)部,即完成了一次冒泡排序 | |
void bubbleSort(int *arr,int arrSize) { | |
for (int i = 0 ; i < arrSize - 1; i++) { | |
for (int j = 1; j < arrSize - i; j++) { | |
if (arr[j-1] > arr[j]) { | |
swap(arr, j-1, j); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment