标签:
冒泡排序:对还未排序的序列,自前向后相邻元素依次比较和调整,让大的元素下沉,小的元素上浮.
时间复杂度: O(n)-->O(n^2)
空间复杂度:O(1)
是否稳定排序:稳定
void bubbleSort(int *array, int n) { int i = n - 1; while (i > 0) { int last_change_index = 0; for (int j = 0; j < i; ++i) { if (array[j] > array[j+1]) { int temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; last_change_index = j; } } i = last_change_index; } }
标签:
原文地址:http://www.cnblogs.com/RoamSpace/p/5667323.html