算法——冒泡排序

2011年11月29日 发表评论 阅读评论

#include <stdio.h>
#define N 10
int main(void)
{
      int a[N] = {5, 1, 8, 4, 0, 2, 9, 3, 6, 7};
      int i, flag, temp, j = N;
      do {
           flag = 0;
           for (i = 1; i < j; i++)
          {
               if (a[i - 1] > a[i])
              {
                   flag = 1;
                   temp = a[i - 1];
                   a[i - 1] = a[i];
                    a[i] = temp;
               }
           }
           j--;
      } while (flag);
      for (i = 0; i < N; i++)
      {
           printf("%5d", a[i]);
      }
     printf("n");
}




本站的发展离不开您的资助,金额随意,欢迎来赏!

You can donate through PayPal.
My paypal id: itybku@139.com
Paypal page: https://www.paypal.me/361way

分类: C/C++/Java/Delphi 标签:
  1. 本文目前尚无任何评论.