Bubble Sort Recursive
#include<stdio.h>
void rbs(int bsa[],int n) //recursive_bubble_sort
{
int i,j,t;
i=n;
if(i>0)
{
for(j=0;j<n-1;j++)
{
if(bsa[j]>bsa[j+1])
{
t=bsa[j];
bsa[j]=bsa[j+1];
bsa[j+1]=t;
}
}
rbs(bsa,n-1);
}
else
{
return;
}
}
int main()
{
printf("enter length of array :- ");
int n;
scanf("%d",&n);
int bsa[n]; //bubble_sort_array
printf("Enter %d element :- ",n);
for(int i=0;i<n;i++)
{
scanf("%d",&bsa[i]);
}
rbs(bsa,n);
printf("Sorted array == ");
for(int i=0;i<n;i++)
{
printf("%d\t",bsa[i]);
}
}
>>>Output
Comments
Post a Comment