Insertion Sort Recursive
#include <stdio.h>
void recursiveInsertionSort(int arr[], int n){
if (n <= 1)
return;
recursiveInsertionSort( arr, n-1 );
int nth = arr[n-1];
int j = n-2;
while (j >= 0 && arr[j] > nth){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = nth;
}
int main()
{
printf("enter length of array :- ");
int n;
scanf("%d",&n);
int arr[n];
printf("Enter %d element :- ",n);
int temp;
/*gujju computervalo*/
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
recursiveInsertionSort(arr,n);
printf("Your sorted array is:- ");
for(int i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
}
output>>
Comments
Post a Comment