#include<stdio.h>
void printarry(int a[], int length, int n);
void printarrydetil(int a[], int length, int d);
void printarry(int a[], int length,int n) {
if (n)
printf("经过排序的数:\t");
else
printf("未经过排序的数:\t");
for (int i = 0; i < length-1; i++)
{
printf("%d\t",a[i]);
}
printf("\n");
}
void printarrydetil(int a[], int length, int d) {
printf("经过第%d轮冒泡排序的数:",d + 1);
for (int i = 0; i < length - 1; i++)
{
printf("%d\t", a[i]);
}
printf("\n");
}
int main(void) {
int arry[] = { 50,46,89,51,23,65,52,62 };
int length = 8;
int n = 0;
printarry(arry, length, n);
for (int i = 0; i < length - 1; i++)
{
int flag;
flag = 0;
for (int j = 0; j < length - 1; j++)
{
if (arry[j] > arry[j + 1])
{
flag = 1;
int t;
t = arry[j + 1];
arry[j + 1] = arry[j];
arry[j] = t;
}
}
printarrydetil(arry,length,i);
if (flag == 0)break;
}
n = 1;
printarry(arry,length,n);
return 0;
}