冒泡排序

闲来无事.

#include<iostream>

void sort1(char *list, int n);

int main()
{
    char list[] = {68, 34, 12, 7, 9, 3, 1};
    sort1(list, sizeof(list));
    return 0;
}

void sort1(char *list, int n)
{
    int flog = 0;
    for (int i = 0; i < n; ++i)
    {
        flog = 0;
        for (int j = 0; j < n - i - 1; ++j)
        {
            if (list[j] > list[j + 1])
            {
                int temp = list[j];
                list[j] = list[j + 1];
                list[j + 1] = temp;
                flog = 1;
            }
            for (int k = 0; k < n; ++k)
            {
                printf("%d", list[k]);
                printf(" ");
            }
            printf("\n");
        }
        if (0 == flog)
        {
            break;
        }
    }
}





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