public static void shiningBubblesort(int[] a) {
int l = 0;
int u = a.length - 1;
while (l < u) {
int up = u;
for (int i = l; i < u; i++) {
if (a[i] > a[i + 1]) {
int t = a[i];
a[i] = a[i + 1];
a[i + 1] = t;
up = i;
}
}
u = up;
int lp = u;
for (int i = u; i > l; i--) {
if (a[i - 1] > a[i]) {
int t = a[i - 1];
a[i - 1] = a[i];
a[i] = t;
lp = i;
}
}
l = lp;
}
}
cHVibGljIHN0YXRpYyB2b2lkIHNoaW5pbmdCdWJibGVzb3J0KGludFtdIGEpIHsKICAgIGludCBsID0gMDsKICAgIGludCB1ID0gYS5sZW5ndGggLSAxOwoKICAgIHdoaWxlIChsIDwgdSkgewogICAgICAgIGludCB1cCA9IHU7CiAgICAgICAgZm9yIChpbnQgaSA9IGw7IGkgPCB1OyBpKyspIHsKICAgICAgICAgICAgaWYgKGFbaV0gPiBhW2kgKyAxXSkgewogICAgICAgICAgICAgICAgaW50IHQgPSBhW2ldOwogICAgICAgICAgICAgICAgYVtpXSA9IGFbaSArIDFdOwogICAgICAgICAgICAgICAgYVtpICsgMV0gPSB0OwogICAgICAgICAgICAgICAgdXAgPSBpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHUgPSB1cDsKCiAgICAgICAgaW50IGxwID0gdTsKICAgICAgICBmb3IgKGludCBpID0gdTsgaSA+IGw7IGktLSkgewogICAgICAgICAgICBpZiAoYVtpIC0gMV0gPiBhW2ldKSB7CiAgICAgICAgICAgICAgICBpbnQgdCA9IGFbaSAtIDFdOwogICAgICAgICAgICAgICAgYVtpIC0gMV0gPSBhW2ldOwogICAgICAgICAgICAgICAgYVtpXSA9IHQ7CiAgICAgICAgICAgICAgICBscCA9IGk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbCA9IGxwOwogICAgfQp9