常用排序算法 1. 冒泡排序快速排序归并排序 1. 冒泡排序 快速排序 void quick_sort(int q[], int l, int r){ if(l >= r)return; int x = q[(l + r) >> 1], i = l - 1, j = r + 1; while(i < j){ do i++; while(q[i] < x); do j--; while(q[j] > x); if(i < j)swap(q[i], q[j]); } quick_sort(q, l, j); quick_sort(q, j + 1, r); } 归并排序 LL mergeSort(int l, int r){ LL res = 0; if(l >= r)return 0; int mid = (l + r) >> 1; res = mergeSort(l, mid) + mergeSort(mid + 1, r); int i = l, j = mid + 1; for(int k = l; k <= r; k++){ if(j > r || ((i <= mid) && a[i] <= a[j]))b[k] = a[i++]; else b[k] = a[j++], res += mid - i + 1; } for(int k = l; k <= r; k++) a[k] = b[k]; return res; }