Posted by: Sourav | August 10, 2015

Insertion sort using recursion in C


#include<stdio.h>
void InsertionSort( int array[],int,int);
void main()
{
//int i=0;int j=0;
int p=0;
int array[5]={25,47,70,31,5};
InsertionSort(array,0,1);
for(p=0;p<5;p++)
printf(“%d\n”,array[p]);

}
void InsertionSort( int array[5], int i, int j)
{
int p=0;
if(i<4)
{
if(array[i]<array[j])
{
int temp=array[i];
array[i]=array[j];
array[j]=temp;

}

if(j<4)
{
j++;
InsertionSort(array,i,j);
}
else
{

i++;
j=(i+1);
InsertionSort(array,i,j);
}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: