#include <stdio.h>
#include <stdlib.h>
int numbers[101],size,i;
void C_sort(int L,int R){
int L_arrow,R_arrow,box,temp;
if(L>R){
return;
}
box=numbers[L];
L_arrow=L;R_arrow=R;
printf("R_arrow=%d\n",R_arrow);
for(i=1;i<=size-1;i++){
if(i==L_arrow)printf("(%d) ",numbers[i]);
else if(i==R_arrow)printf("[%d] ",numbers[i]);
else printf("%d ",numbers[i]);
}
for(i=0;i<=size-1;i++)printf("%d ",numbers[i]);
printf("\n");
while(L_arrow!=R_arrow){
while(numbers[R_arrow]>=box&&L_arrow<R_arrow){
R_arrow--;
printf("R_arrow=%d\n",R_arrow);
for(i=0;i<=size-1;i++)printf("%d ",numbers[i]);
}
while(numbers[L_arrow]<=box&&L_arrow<R_arrow){
L_arrow++;
for(i=0;i<=size-1;i++)printf("%d ",numbers[i]);
}
if(L_arrow<R_arrow){
temp=numbers[R_arrow];
numbers[R_arrow]=numbers[L_arrow];
numbers[L_arrow]=temp;
for(i=0;i<=size-1;i++)printf("%d ",numbers[i]);
}
/*for(i=1;i<=size-1;i++){
if(i==L_arrow)printf("(%d) ",numbers[i]);
else if(i==R_arrow)printf("[%d] ",numbers[i]);
else printf("%d ",numbers[i]);
}*/
//printf("\n");
}
numbers[L]=numbers[L_arrow];
numbers[L_arrow]=box;
for(i=1;i<=size-1;i++)printf("%d ",numbers[i]);
printf("\n");
C_sort(L,L_arrow-1);
C_sort(L_arrow+1,R);
}
int main()
{
int i;
scanf("%d",&size);
for(i=0;i<=size-1;i++)scanf("%d",&numbers[i]);
//for(i=0;i<=size-1;i++)printf("%d ",numbers[i]);//测试代码,此时输出已不正常
C_sort(0,size-1);
for(i=1;i<=size-1;i++)printf("%d ",numbers[i]);
system("pause");
return 0;
}有一些是测试代码显示过程。编译通过,然后结果明显错误,从过程来看也没有R_arrow的踪迹。Why?错误太随机了!!
目前暂无任何回答
- 0 回答
- 1 关注
- 1270 浏览
添加回答
举报
0/150
提交
取消