常见排序之冒泡排序

#include<stdio.h>

int Array[] = {2,0,1,3,4,8,6,7,5,9};

void Bubble_Sort(int *Array_Sort)注:此处可写int Array_Sort[10]

{

      int i,j;

      int temp;

      for(i = 0; i < 10-1; i++)

      {

           for(j = 0; j < 10-i-1; j++)

           {

                 if(Array_Sort[j]>Array_Sort[j+1]) 注:此处改为<变为大到小排列

                 {

                      temp = Array_Sort[j];

                      Array_Sort[j] = Array_Sort[j+1];

                      Array_Sort[j+1] = temp;

                 }

           }

      }

}

int main(void)

{

      int j = 0;

      Bubble_Sort(Array);

      for(j = 0; j < 10; j++)

      {

           printf("%d\r\n",Array[j]);

      }

      return 0;

}

猜你喜欢

转载自www.cnblogs.com/muzixiaofeng/p/10088597.html
今日推荐