C语言经典算法--冒泡详细排序流程代码:
#include <stdio.h>
#define N 10
int main(int argc, const char * argv[])
{
int i,j,k,temp,array[N];
for(i=0;i<N;i++)
{
scanf("%d",array+i);
}
printf("冒泡排序前: ");
for (i=0; i<N;i++) {
printf("%2d",array[i]);
}
printf(" ");
for (j=0;j<N-1; j++) {
printf("第%d趟排序后:",j+1);
for (k=0;k<N-1-j; k++)
{
if(array[k]>array[k+1])
{
temp=array[k];
array[k]=array[k+1];
array[k+1]=temp;
}
}
for(i=0; i<N; i++)
{
printf("%2d",array[i]);
}
printf(" ");
}
printf("冒泡排序后: ");
for (i=0; i<N; i++) {
printf("%2d",array[i]);
}
printf(" ");
return 0;
}