1.选择排序
void sort(int a[], int l, int r){
for(int i= l; i<=r; i++){
for(int j=i+1; j<=r; j++){
if(a[i]>a[j]) swap(a[i],a[j]);
}
}
}
2.快速排序
void quick_sort(int q[],int l,int r) {
if (l >= r) return;
int i = l - 1;
int j = r + 1;
int x = q[(l + r) / 2];
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);
}
3.归并排序
void merge_sort(int q[], int l, int r){
if(l>=r) return;
int mid= (l + r )/2;
merge_sort(q,l,mid),merge_sort(q,mid+ 1,r);
int k=0,i=l,j=mid+ 1;
while(i<=mid && j<=r) {
if (q[i]<=q[j]) tmp[k++]=q[i++];
else tmp[k++]=q[j++];
}
while(i<=mid) tmp[k++]=q[i++];
while(j<=r) tmp[k++]=q[j++];
for ( k = 0, i=l;i<=r;k++,i++ ) q[i]=tmp[k];
//for ( i=l,j=0;i<=r;i++,j++ ) q[i]=tmp[j];
}