void quick_sort(int *data, int left, int right)
{
int k;
int i, j, pivot;
i = left;
j = right;
pivot = left;
if(i >= j)
return;
while(i < j)
{
while(data[++i] < data[pivot])
{
if(i >= right)
break;
}
while(data[j] > data[pivot])
{
j--;
if(j <= left)
break;
}
if(i < j)
swap(data, i, j);
}
swap(data, pivot, j);
quick_sort(data, left, j - 1);
quick_sort(data, j + 1, right);
}
void swap(int *data, int i, int j)
{
int tmp;
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
[c소스] 퀵 정렬(quick sort)
2010. 7. 29. 15:13