zoukankan      html  css  js  c++  java
  • 12月8号数组实现冒泡法

    #include <stdio.h>

    //冒泡排序

    void bubbleSort(int array[], int elementCount){

        int temp;

        for (int i = 0; i < elementCount; i ++) {

            for (int j = elementCount - 2; i <= j; j --) {

                //比较jj+1对应的数字大小

                if (array[j] > array[j+1]) {

                    temp = array[j];

                    array[j] = array[j+1];

                    array[j+1] = temp;

                    

                }

            }

        }

    }

     

    int main(int argc, const char * argv[]) {

        int array[5]={};

        printf("请输入数据5:");

        for (int i = 0; i < 5; i++) {

            scanf("%d",&array[i]);

        }

        

        //冒泡排序

        bubbleSort(array, 5);

        for (int i = 0; i < 5; i++) {

            printf("%d ", array[i]);

        }

        printf(" ");

        return 0;

    }

  • 相关阅读:
    hdu 1296
    hdu 2101
    hdu 2100
    codeforces 3C
    codeforces 2A
    codeforces 1B
    codeforces 811B
    关于sws_scale() 段错误
    cf 1288 D. Minimax Problem (好题)(二分+二进制表状态+枚举)
    opencv4 鼠标事件 鼠标画线条
  • 原文地址:https://www.cnblogs.com/hmzxwky/p/5030014.html
Copyright © 2011-2022 走看看