很久没写冒泡法排序了,
感觉自己现在的心情很像冒泡,既不生气,也不变傻,感觉像有一个一个的泡泡往上涌,或许这种心情就叫失落
那就写个冒泡法排序吧,说不定哪天的笔试叫我冒泡法排序呢
#include <stdio.h>
#include <stdlib.h>

#define N 8

int main()
{
         int a[N]={8,2,3,9,7,3,2,5};
         int i,j,k;
         int t;
    
         printf("before sequence:");
         for(i=0;i<N;i++)
         {
               printf("%d ",a[i]);    
         }
         printf("\n");
    
         for(i=0;i<N;i++)
         {
                    for(j=0;j<(N-1)-i;j++)
                    {
                             if(a[j]>a[j+1])
                             {
                                        t=a[j];
                                        a[j]=a[j+1];
                                        a[j+1]=t;            
                             }
                    }
                    for(k=0;k<N;k++)
                    {
                              printf("%d ",a[k]);    
                    }
                    printf("\n");
        }

         printf("after sequence:");
         for(i=0;i<N;i++)
         {
                    printf("%d ",a[i]);    
         }
         printf("\n");
         return 0;
}
没什么滑头,就是一次一个大数沉底,或许你也可以理解为一个泡沫冒上来,呵呵