1.C++实现
#include//打印数组 void printArray(int* array, int count); void bubble_sort(int* array, int count) { bool needsort = false; int temp = 0; for(int j=0;j array[i + 1]) { temp = array[i]; array[i] = array[i + 1]; array[i + 1] = temp; needsort = true; } } if (!needsort) break; } } int main() { int array[] = {8,20,9,7,21,50,11,65,73,15}; printf("排序前:n"); printArray(array, sizeof(array) / sizeof(int)); //冒泡排序 bubble_sort(array, sizeof(array) / sizeof(int)); printf("排序后:n"); printArray(array, sizeof(array) / sizeof(int)); } void printArray(int* array, int count) { for (int i = 0; i < count; i++) { printf("%dt", array[i]); } printf("n"); }
2.时间复杂度及空间复杂度
| 复杂度 | 最好 | 最坏 | 平均 |
| 时间复杂度 | O(n) | O() | O() |
| 空间复杂度 | O(1) | O(1) | O(1) |



