What do you think of this piece of code ? This is an implementation of quick sort in C, but I'm not sure about the quality and correctness.
#include <stdio.h>
void swap(int tab[], int a, int b)
{
int temp = tab[a];
tab[a] = tab[b];
tab[b] = temp;
}
void quickSort(int tab[], int begin, int end)
{
int left = begin-1;
int right = end+1;
const int pivot = tab[begin];
if(begin >= end)
return;
while(1)
{
do right--; while(tab[right] > pivot);
do left++; while(tab[left] < pivot);
if(left < right)
swap(tab, left, right);
else break;
}
quickSort(tab, begin, right);
quickSort(tab, right+1, end);
}
int main(void)
{
int tab[5] = {5, 3, 4, 1, 2};
int i;
quickSort(tab, 0, 4);
for(i = 0; i < 5; i++)
{
printf("%d ", tab[i]);
}
putchar('\n');
return 0;
}
Is it the standard way of implementing a quick sort in C ?