#include #include int a[7] = { 4,2,3,1,6,7,8 };int b[7] = { 4,2,3,1,6,7,8 };void bubble_sort(int* a, int len) // 优化版本的冒泡排序{for (int end = len - 1; end > 0; end--){int sortIndex = 1;for (int begin = 1; begin <= end; begin++){if (a[begin] < a[begin - 1]){int b = a[begin];a[begin] = a[begin - 1];a[begin - 1] = b;sortIndex = begin;}}end = sortIndex;}for (int i = 0; i < len; i++){printf("%d_", a[i]);}printf("n");}void selset_sort(int* a, int len) // 选择排序,每一轮将最大数字与该轮的最后一个位置交换{for (int end = len - 1; end > 0; end--){int maxindex = 0;for (int begin = 1; begin <= end; begin++){if (a[maxindex] <= a[begin])// 存在数字比 maxindex 那个数字大,则记录下标 {maxindex = begin;}}int temp = a[maxindex];a[maxindex] = a[end];a[end] = temp;}for (int i = 0; i < len; i++){printf("%d_", a[i]);}}int main(int argc, char** argv){bubble_sort(a, sizeof(a) / sizeof(a[0]));selset_sort(b, sizeof(b) / sizeof(b[0])); return 1;}