用快速排序写出程序对下列序列进行排序,49,38,65,97,13,27,49
答案:1 悬赏:50 手机版
解决时间 2021-01-16 16:51
- 提问者网友:练爱
- 2021-01-15 20:28
用快速排序写出程序对下列序列进行排序,49,38,65,97,13,27,49
最佳答案
- 五星知识达人网友:罪歌
- 2021-01-15 21:07
提供C语言的快速排序代码供参考
#include
#include
#include
void quicksort(int a[], int low, int high)
{
if (low >= high) return;
int first = low;
int last = high;
int key = a[first];
while (first {
while (first=key) --last;
a[first] = a[last];
while (first a[last] = a[first];
}
a[first] = key;
quicksort(a, low, first - 1);
quicksort(a, first + 1, high);
}
void print(int a[], int n)
{
int i;
for(i=0;i {
printf("%d ",a[i]);
}
}
int main()
{
int a[] = {49,38,65,97,13,27,49};
quicksort(a,0,6);
printf("排序结果:
");
print(a,7);
return 0;
}
#include
#include
#include
void quicksort(int a[], int low, int high)
{
if (low >= high) return;
int first = low;
int last = high;
int key = a[first];
while (first
while (first
a[first] = a[last];
while (first
}
a[first] = key;
quicksort(a, low, first - 1);
quicksort(a, first + 1, high);
}
void print(int a[], int n)
{
int i;
for(i=0;i
printf("%d ",a[i]);
}
}
int main()
{
int a[] = {49,38,65,97,13,27,49};
quicksort(a,0,6);
printf("排序结果:
");
print(a,7);
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯