文章标题

来源:互联网 发布:郑中基别爱我知乎 编辑:程序博客网 时间:2024/06/06 01:28

排序

int a[10] = {1, 3, 2, 6, 5, 4, 7, 8, 9, 10};    int count = 10;    for (int i = 0; i < count - 1; i++) {        for (int j = 0; j < count - 1 - i; j++) {            if (a[j] > a[j + 1]) {                int t = a[j];                a[j] = a[j + 1];                a[j + 1] = t;            }        }    }    for (int i = 0; i < count; i++) {        printf("%d\n", a[i]);    }    int temp = 0, j = 0;    for (int i  = 0; i < count; i++) {        temp = a[i];        j = i - 1;        while ((j >= 0) && (a[j] > temp)) {            a[j + 1] = a[j];            j--;        }        if (j != i - 1) {            a[j + 1] = temp;        }    }    for (int i = 0; i < count; i++) {        printf("%d\n", a[i]);    }
0 0