zoukankan      html  css  js  c++  java
  • 冒泡排序

    1、实现思想

     

     2、实现代码

     1 #include <stdio.h>
     2 void bulubulu_sort(int *array, int len)
     3 {
     4     int temp;
     5     for (int i = 0; i < len - 1; i++)
     6     {
     7         for (int j = 0; j < len - 1; j++)
     8         {
     9             if (array[j] < array[j + 1])
    10             {
    11                 temp = array[j];
    12                 array[j] = array[j + 1];
    13                 array[j + 1] = temp;
    14             }
    15         }
    16     }
    17 }
    18 int main(void)
    19 {
    20     int array[] = {1, 2, 3, 4, 5, 6, 7};
    21     int len = sizeof(array) / sizeof(array[0]);
    22     bulubulu_sort(array, len);
    23     for (int i = 0; i < len; i++)
    24     {
    25         printf("%d  ", array[i]);
    26     }
    27     return 0;
    28 }
    29 /* 
    30 输出
    31 ————————————————————————————
    32 7  6  5  4  3  2  1 
    33 ————————————————————————————
    34  */

    总结:

    其实冒泡算法和简单排序算法的思想都一样,找到「最值」然后将「最值」放到有序区

  • 相关阅读:
    HDU 2196 Computer
    HDU 1520 Anniversary party
    POJ 1217 FOUR QUARTERS
    POJ 2184 Cow Exhibition
    HDU 2639 Bone Collector II
    POJ 3181 Dollar Dayz
    POJ 1787 Charlie's Change
    POJ 2063 Investment
    HDU 1114 Piggy-Bank
    Lca hdu 2874 Connections between cities
  • 原文地址:https://www.cnblogs.com/coderon/p/13394425.html
Copyright © 2011-2022 走看看