ToSWAP
void ToSWAP(int& a, int& b) {
int t = a;
a = b;
b = t;
}
퀵정렬 1
void quickSort(int* data, int start, int end)
{
if (start >= end) return;
int pivot = start;
int i = start + 1;
int j = end;
while (i <= j)
{
while (data[i] <= data[pivot]) i++;
while (data[j] >= data[pivot] && j > start) j--;
if (i > j) ToSWAP(data[pivot], data[j]);
else ToSWAP(data[j], data[i]);
quickSort(data, start, j - 1);
quickSort(data, j + 1, end);
}
}
퀵정렬 2
void quickSort2(int* data, int start, int end)
{
if (start >= end) return;
int pivot, front, last, tmp;
pivot = start;
front = start + 1;
last = end;
while (front <= last)
{
while (data[front] <= data[pivot] && front <= end) front++;
while (data[last] > data[pivot] && last >= start) last--;
if (front > last) break;
else ToSWAP(data[front], data[last]);
}
ToSWAP(data[last], data[pivot]);
quickSort2(data, start, last - 1);
quickSort2(data, last + 1, end);
}