嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
冒泡排序的动态显示过程,C语言实现
// 15个数的冒泡排序,图形表示
int BubbleSort()
{
#define SNUM 16
srand((unsigned int)time(NULL));
int data[SNUM] = { 0 }, copy[SNUM] = { 0 };
int temp;
int num1=0, num2=0,num3=0;
Gotoxy(0, 0);
printf("生成序列: ");
for (int i = 0; i < SNUM; i )
{
data[i] = 1 rand()%16;
copy[i] = data[i];
printf("%d ",data[i]);
}
printf("\n");
for (int i = 1; i < SNUM; i )
{
for (int j = 0; j < SNUM - i; j )
{
if (data[j] > data[j 1])
{
temp = data[j];
data[j] = data[j 1];
data[j 1] = temp;
num2 ;
num3 = 3;
}
num1 ;
num3 ;
}
}
printf("顺序排序: ");
for (int i = 0; i < SNUM; i )
{
printf("%d ",data[i]);
}
printf("\n");
printf("比较次数:%7d,擦写次数:%7d*2,遍历语句:%7d\n",num1,num2,num3);
for (int i = 0; i < 20; i )
{
printf(" -- ");
}
printf("\n");
for (int i = 0; i < SNUM; i )
{
clr_row(1,i 5);
putpic(0,copy[i]);
}
Sleep(2000);
for (int i = 1; i < SNUM; i )
{
for (int j = 0; j < SNUM - i; j )
{
currentpic(j 5);
if (copy[j] > copy[j 1])
{
temp = copy[j 1];
copy[j 1] = copy[j];
clr_row(1, 1 j 5);
putpic(0,copy[j 1]);
copy[j] = temp;
clr_row(1,j 5);
putpic(1,copy[j]);//函数执行完才输出显示?
}
clr_currentpic(j 5);
}
}
Gotoxy(0, 21);
for (int i = 0; i < 20; i )
{
printf(" -- ");
}
printf("\n");
return 0;
}