0

I understand that any iterative function can be written recursively, but I still don't quite understand how to write it as a recursive function.

This function receives an array (elements) and a int (number of elements), and sorts them from lower to higher, but I don't get how to make it recursive, any help would be appreciated!

void ShellSort(int *arr, int num){
    for (int i = num / 2; i > 0; i = i / 2)
    {
        for (int j = i; j < num; j++)
        {
            for(int k = j - i; k >= 0; k = k - i)
            {
                if (arr[k+i] >= arr[k])
                {
                    break;
                }
                else
                {
                    arr[k]=arr[k] + arr[k+i];
                    arr[k+i]=arr[k] - arr[k+i];
                    arr[k]=arr[k] - arr[k+i];
                }
            }
        }
    }
    return ;
}
Cris
  • 11
  • 2
  • Recursion is where a method calls itself from within its definition.. Your method as you have pasted it does not call itself. Nowhere in the body of your method does it say again ShellSort() – Kevon Nov 09 '22 at 18:41

0 Answers0