冒泡排序的方法

    //冒泡排序法

    int arr[] = {123,432,4531,123,43,35,23,12,4,45,23,5,1,0};
    int count = sizeof(arr)/sizeof(arr[0]);
    int temp = 0;

    for (int i = 0; i < count - 1; i ++)
    {
        for (int j = 0; j < count - 1 - i; j ++)
        {
            if (arr[j] < arr[j + 1])
            {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }

    printf("由小到大顺序为:\n");

    for (int k = 0; k < count ; k ++)
    {
        printf("%d ",arr[k]);
    }

你可能感兴趣的:(冒泡排序的方法)