class Main {
int[] data = {4, 7, 10, 2, 5};
sort(data);
for(int i = 0; i < data.length; i++) {
System.
out.
print(data
[i
]+" "); }
}
public static void sort(int[] data) {
if (data != null) {
quickSort(data, data.length);
}
}
private static void quickSort(int[] data, int count) {
if (count <= 1) {
return;
}
int[] largeData = new int[count];
int[] smallData = new int[count];
int largeCount = 0;
int smallCount = 0;
int pivot = data[0];
for (int index = 1; index < count; index ++) {
if (data[index] > pivot) {
largeData[largeCount] = data[index];
largeCount ++;
}
else {
smallData[smallCount] = data[index];
smallCount ++;
}
}
quickSort(largeData, largeCount);
quickSort(smallData, smallCount);
int sortedIndex = 0;
for (int smallIndex = 0; smallIndex < smallCount; smallIndex ++) {
data[sortedIndex] = smallData[smallIndex];
sortedIndex ++;
}
data[sortedIndex] = pivot;
sortedIndex ++;
for (int largeIndex = 0; largeIndex < largeCount; largeIndex ++) {
data[sortedIndex] = largeData[largeIndex];
sortedIndex ++;
}
}
}
Y2xhc3MgTWFpbiB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24gewoJCWludFtdIGRhdGEgPSB7NCwgNywgMTAsIDIsIDV9OwoJCXNvcnQoZGF0YSk7CgkJZm9yKGludCBpID0gMDsgaSA8IGRhdGEubGVuZ3RoOyBpKyspIHsKCQkJU3lzdGVtLm91dC5wcmludChkYXRhW2ldKyIgIik7CgkJfQoJfQoJcHVibGljIHN0YXRpYyB2b2lkIHNvcnQoaW50W10gZGF0YSkgewoJCWlmIChkYXRhICE9IG51bGwpIHsKCQkJcXVpY2tTb3J0KGRhdGEsIGRhdGEubGVuZ3RoKTsKCQl9Cgl9Cglwcml2YXRlIHN0YXRpYyB2b2lkIHF1aWNrU29ydChpbnRbXSBkYXRhLCBpbnQgY291bnQpIHsKCQlpZiAoY291bnQgPD0gMSkgewoJCQlyZXR1cm47CgkJfQoJCWludFtdIGxhcmdlRGF0YSA9IG5ldy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