#include <stdio.h> #include <stdlib.h> int numbers[],size; void C_sort(int L,int R){ int L_arrow,R_arrow,box; if(L>R){ return; } box=numbers[L]; L_arrow=L;R_arrow=R; while(L_arrow!=R_arrow){ while(numbers[R_arrow]>=box){ if(L_arrow<R_arrow){ R_arrow--; } else { break; } } while(numbers[L_arrow]<=box){ if(L_arrow<R_arrow){ L_arrow++; } else { break; } } if(L_arrow<R_arrow){ numbers[L_arrow]=numbers[L_arrow]+numbers[R_arrow]; numbers[R_arrow]=numbers[L_arrow]-numbers[R_arrow]; numbers[L_arrow]=numbers[L_arrow]-numbers[R_arrow]; } } numbers[L]=numbers[L_arrow]; numbers[L_arrow]=box; C_sort(L,L_arrow-1); C_sort(L_arrow+1,R); } int main() { int i; scanf("%d",&size); for(i=1;i<=size;i++)scanf("%d",&numbers[i]); for(i=1;i<=size;i++)printf("%d",numbers[i]);//测试代码,此时输出已不正常 C_sort(1,size); for(i=1;i<=size;i++)printf("%d",numbers[i]); system("pause"); return 0; }
就这个,编译倒没问题,运行的时候,错误非常随机,比如98765甚至要输入两次还是错的!!为什么?
Camel97
相关分类