void swap(BYTE *a,BYTE *b)
{
BYTE tmp;
if ( a != b )
{
tmp = *a;
*a = *b;
*b = tmp;
}
}
void quicksort(BYTE *arr, int left, int right)
{
if (left < right)
{
BYTE v = arr[right];
int i = left - 1,j = right,p = left - 1,q = right,k=0;
while (1)
{
while (arr[++i] < v);
while (arr[--j] > v)
if(j==left)
break;
if (i >= j)
break;
swap(&arr[i], &arr[j]);
if(arr[i] == v)
{
p++;
swap(&arr[p],&arr[i]);
}
if(arr[j] == v)
{
q--;
swap(&arr[q],&arr[j]);
}
}
swap(&arr[i],&arr[right]);
j = i - 1;
i++;
for(k=left; k<=p; k++,j--)
swap(&arr[k],&arr[j]);
for(k=right-1; k>=q; k--,i++)
swap(&arr[k],&arr[i]);
quicksort(arr,left,j);
quicksort(arr,i,right);
}
}
void QuickSort(BYTE *array,int length)
{
quicksort(array,0,length-1);
}