shaker排序法,运行时怎么不让程序结果刷屏?
源程序:#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX 10
#define SWAP(x,y) {int t;t=x;x=y;y=t;}
void shakersort(int []);
int main()
{
int number[MAX]={0};
int i;
srand(time(NULL));
printf("排序前");
for(i=0;i<MAX;i++)
{
number[i]=rand()%100;
printf("%d ",number[i]);
}
shakersort(number);
printf("\n");
return 0;
}
void shakersort(int number[])
{
int i,left=0,right=MAX-1,shift=0;
while(left<right)
{
//向右进行气泡排序
for(i=left;i<right;i++)
{
if(number[i]>number[i+1])
{
SWAP(number[i],number[i+1]);
shift=i;
}
}
right=i;
printf("\n往右排序");
for(i=0;i<MAX;i++)
{
printf("%d ",number[i]);
}
//向左进行气泡排序
for(i=right;i>left;i--)
{
if(number[i]<number[i-1])
{
SWAP(number[i],number[i-1]);
shift=i;
}
}
left=shift;
printf("\n向左排序");
for(i=0;i<MAX;i++)
{
printf("%d ",number[i]);
}
}
}
结果如下: