summaryrefslogtreecommitdiff
path: root/anim/tools/sort.c
blob: 5816390769e60c58f4db02d8c210c867b61b3d78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int a[8] = {4, 9, 17, 31, 12, 26, 5, 20};

void swap(int *x, int *y) {
    int t = *x;
    *x = *y;
    *y = t;
}

void sort(int n) {
    for (int i = 1; i < n; i++) {
        int j = i;
        while (j > 0 && a[j - 1] > a[j]) {
            swap(&a[j - 1], &a[j]);
            j--;
        }
    }
}

int main(void) {
    sort(8);
    return 0;
}