#includevoid bubble_sort(int arr[], int n);///稳定void insert_sort(int arr[],int n);///稳定void selection_sort(int arr[],int n);///不稳定void quick_sort(int arr[],int start,int end);///不稳定int main(){ int a[105]; int n; scanf("%d",&n); int i; for(i=0;i arr[j]){ min = j; } } if(min != i){ int tmp; tmp = arr[min]; arr[min] = arr[i]; arr[i] = tmp; } }}///冒泡排序,时间复杂度O(n^2),是稳定的void bubble_sort(int arr[], int n){ int i, j, temp; for (j = 0; j < n - 1; j++) for (i = 0; i < n - 1 - j; i++) { if(arr[i] < arr[i + 1]) { temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; } }}///快速排序,时间复杂度O(n*log(n)),是不稳定的void swap(int arr[],int i,int j){ int tmp; tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp;}void quick_sort(int arr[],int start,int end) ///end代表数组中最后一个元素的位置{ if(start >= end){ return ; } int x; int i = start; int j = end; x = arr[start]; while(i != j){ while(i < j && arr[j] > x){ j--; } swap(arr,i,j); while(i < j && arr[i] <= x){ i++; } swap(arr,i,j); } quick_sort(arr,start,i-1); quick_sort(arr,i+1,end);}///插入排序,时间复杂度O(n^2),是稳定的void insert_sort(int arr[],int n){ int i=0; int tmp; for(i=1;i tmp && j >= 0){ arr[j+1] = arr[j]; j--; } arr[++j] = tmp; }}