Quote Originally Posted by TechHigh
Dave_Sinkula : it simply acts like going in infinite loop , meaning it enters the algorithm and dies there . I didn't dear to debug on an 2000 numbers input
I have this:
Code:
long array[1700];

int main(void)
{
   size_t i;
   srand(time(0));
   for ( i = 0; i < sizeof array / sizeof *array; ++i )
   {
      array[i] = rand();
   }
   quickSort(array, 0, sizeof array / sizeof *array);
   return 0;
}
Good enough for testing, except I don't have your swap function.

But debugging code generally involves all of the code that demonstrates the issue. Rather than me or others "inventing" code that is sitting right in front of you, it is just easier to strip things down to the bare minimum and find the real reason.

Yes you could be blowing the stack. Or it could be something else. Do you want to fix it, or do you just want to blame this or that?

If you want to fix it and improve your algorithm so that it can handle millions of elements, perhaps post the code?

For example, the following works (for me ) using the standard library's qsort:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int cmp(const void *a, const void *b)
{
   const long *x = a, *y = b;
   return (*x > *y) - (*x < *y);
}

void init(long *array, size_t size)
{
   size_t i;
   for ( i = 0; i < size; ++i )
   {
      *array++ = rand();
   }
}

void print(const long *array, size_t size)
{
   size_t i;
   for ( i = 0; i < size; ++i )
   {
      printf("%ld\n", *array++);
   }
}

long array[1000000];

int main(void)
{
   srand(time(0));
   init (array, sizeof array / sizeof *array);
   qsort(array, sizeof array / sizeof *array, sizeof *array, cmp);
   print(array, sizeof array / sizeof *array);
   return 0;
}
Disclaimer: I never waited for all 1 million values to print.