How does recursion work in the below program? -


/* head ends here */ void quicksort(int ar_size, int *  ar)  {   int i, j, t;   int pivot = 0;   if((ar_size == 0) || (ar_size == 1))    {     return;   }    int a[1000], b[1000], s1 = 0, s2 = 0;   for(i = 1; < ar_size; i++)   {     if(ar[i] <= ar[pivot])      {       a[s1++] = ar[i];     }     else      {       b[s2++] = ar[i];     }   }    quicksort(s1, a);   quicksort(s2, b);    t = ar[pivot];    for(i = 0; < s1; i++)    {     ar[i] = a[i];   }   ar[i] = t;    for(i = 0; < s2; i++)   {     ar[s1 + +1] = b[i];   }    for(i = 0; i< ar_size; i++)   {     printf("%d ", ar[i]);   }    printf("\n"); }  /* tail starts here */ int main()  {   int _ar_size;    scanf("%d", &_ar_size);    int _ar[_ar_size], _ar_i;    for(_ar_i = 0; _ar_i < _ar_size; _ar_i++)    {      scanf("%d", &_ar[_ar_i]);    }    quicksort(_ar_size, _ar);    return 0; } 

if understand correctly want understand how quicksort works. suggest take @ this video.

now recursion. idea simple. have function specific in process calls itself. fine example factorial of number.

int factorial(int x) {     if(x = 0)         return 1;      return x * factorial(x - 1); } 

so if call factorial(4); factorial(4)= 4 * factorial(3)= 4 * 3 * factorial(2) = 4 * 3 * 2 * factorial(1) = 4 * 3 * 2 * 1 * factorial(0) = 4 * 3 * 2 * 1 * 1 = 24