文章
36
粉丝
0
获赞
5
访问
22.9k
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
int partition(int a[],int low,int high){
int pap=a[low];
while(low<high){
while(low<high&&a[high]>=pap) high--;
a[low] = a[high];
while(low<high&&a[low]<=pap) low++;
a[high]=a[low];
}
a[low]=pap;
return low;
}
void quicksort(int a[],int low,int high){
if(low<high){
int position = partition(a,low,high);
quicksort(a,position+1,high);
quicksort(a,low,position-1);
}
}
void shell_sort1(int a[], int n) {
int gap = 5; // 固定步长为5
int i, j;
// 只进行一趟排序
for (i = gap; i < n; i++) {
// 在当前步长下执行插入排序
int tmp = a[i];
for (j = i; j >= gap && a[j - gap] > tmp; j -= gap) {
a[j] = a[j - gap];
}
a[j] = tmp;
}
}
// 合并两个有序子数组
void merge(int arr[], int...
登录后发布评论
暂无评论,来抢沙发