Posted by: Sourav | August 10, 2015

BubbleSort using recursion in C


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

}
void BubbleSort( int array[5], int i, int j)
{
int p=0;
if(j<i)
{
if(array[j]>array[j+1])
{

int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;

}

if(j==(i-1))
{

i–;
j=0;

BubbleSort(array,i,j);
}
else
{

j++;
BubbleSort(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: