Play and learn 300 000+ tabs online

Thursday, August 12, 2010

QuickSort Program in C

void swap(int *a, int *b)
{
int t=*a; *a=*b; *b=t;
}
void sort(int arr[], int beg, int end)
{
if (end > beg + 1)
{
int piv = arr[beg], l = beg + 1, r = end;
while (l < r)
{
if (arr[l] <= piv)
l++;
else
swap(&arr[l], &arr[--r]);
}
swap(&arr[--l], &arr[beg]);
sort(arr, beg, l);
sort(arr, r, end);
}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.