#include <stdio.h>
void bubble_sort(int *p, int n)
{
int t, i, j;
for (i = 0; i < n - 1; i++) {
for (j = n - 1; j > i; j--) {
if (*(p + j - 1) > *(p + j)) {
t = *(p + j);
*(p + j) = *(p + j - 1);
*(p + j - 1) = t;
}
}
}
}
int main()
{
int a[] = { 2, 1, 7, 3, 6, 4, 8, 5, 9 };
int n = sizeof(a) / sizeof(a[0]);
int i;
bubble_sort(a, n);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIGJ1YmJsZV9zb3J0KGludCAqcCwgaW50IG4pCnsKICAgIGludCB0LCBpLCBqOwoKICAgIGZvciAoaSA9IDA7IGkgPCBuIC0gMTsgaSsrKSB7CiAgICAgICAgZm9yIChqID0gbiAtIDE7IGogPiBpOyBqLS0pIHsKICAgICAgICAgICAgaWYgKCoocCArIGogLSAxKSA+ICoocCArIGopKSB7CiAgICAgICAgICAgICAgICB0ID0gKihwICsgaik7CiAgICAgICAgICAgICAgICAqKHAgKyBqKSA9ICoocCArIGogLSAxKTsKICAgICAgICAgICAgICAgICoocCArIGogLSAxKSA9IHQ7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCkKewogICAgaW50IGFbXSA9IHsgMiwgMSwgNywgMywgNiwgNCwgOCwgNSwgOSB9OwogICAgaW50IG4gPSBzaXplb2YoYSkgLyBzaXplb2YoYVswXSk7CiAgICBpbnQgaTsKCiAgICBwcmludGYoIuWFgyBhID0geyAiKTsgZm9yIChpID0gMDsgaSA8IG47IGkrKykgeyBwcmludGYoIiVkICIsIGFbaV0pOyB9IHByaW50ZigifVxuIik7CiAgICBidWJibGVfc29ydChhLCBuKTsKICAgIHByaW50Zigi5b6MIGEgPSB7ICIpOyBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7IHByaW50ZigiJWQgIiwgYVtpXSk7IH0gcHJpbnRmKCJ9XG4iKTsKCiAgICByZXR1cm4gMDsKfQo=