哪位大神能够详尽地解释一下快速排序C语言算法的原理,小白跪谢 20
#include<stdio.h>intmain(){inta[11],i;printf("pleaseinput10numbers:");for(i=1;i<=10;i...
#include<stdio.h>
int main()
{
int a[11],i;
printf("please input 10 numbers:");
for(i=1;i<=10;i++)
scanf("%d",&a[i]);
qusort(a,1,10);
printf("the sorted sequence:");
for(i=1;i<=10;i++)
printf("%5d",a[i]);
return 0;
}
void qusort(int *a, int left, int right)
{
if(left >= right)
{
return ;
}
int i = left;
int j = right;
int key = a[left];
while(i < j)
{
while(i < j && key <= a[j])
{
j--;
}
a[i] = a[j];
while(i < j && key >= a[i])
{
i++;
}
a[j] = a[i];
}
a[i] = key;
qusort(a, left, i - 1);
qusort(a, i + 1, right);
} 展开
int main()
{
int a[11],i;
printf("please input 10 numbers:");
for(i=1;i<=10;i++)
scanf("%d",&a[i]);
qusort(a,1,10);
printf("the sorted sequence:");
for(i=1;i<=10;i++)
printf("%5d",a[i]);
return 0;
}
void qusort(int *a, int left, int right)
{
if(left >= right)
{
return ;
}
int i = left;
int j = right;
int key = a[left];
while(i < j)
{
while(i < j && key <= a[j])
{
j--;
}
a[i] = a[j];
while(i < j && key >= a[i])
{
i++;
}
a[j] = a[i];
}
a[i] = key;
qusort(a, left, i - 1);
qusort(a, i + 1, right);
} 展开
1个回答
2015-11-29
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询