Choose the correct function for recursive insertion sort?
A.
B.
C.
D.
A.
Code:
void RecInsertionSort(int arr[], int n)
{
if (n <= 1)
return;
RecInsertionSort( arr, n-1 );
int key = arr[n-1];
int j = n-2;
while (j >= 0 && arr[j] > key)
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = key;
}
Code:
void RecInsertionSort(int arr[], int n)
{
if (n < 1)
return;
RecInsertionSort( arr, n-1 );
int key = arr[n-1];
int j = n-2;
while (j >= 0 || arr[j] > key)
{
arr[j+1] = arr[j];
j--;
}
arr[j] = key;
}
Code:
void RecInsertionSort(int arr[], int n)
{
if (n <1)
return;
RecInsertionSort( arr, n-1 );
int key = arr[n-1];
int j = n-2;
while (j >= 0 && arr[j] > key)
{
arr[j+1] = arr[j];
j--;
}
arr[j] = key;
}
Code:
void RecInsertionSort(int arr[], int n)
{
if (n <= 1)
return;
RecInsertionSort( arr, n-1 );
int key = arr[n-1];
int j = n-1;
while (j >= 0 || arr[j] > key)
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = key;
}