forked from nitinsultania/CPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecbubblesort.c
More file actions
44 lines (38 loc) · 720 Bytes
/
recbubblesort.c
File metadata and controls
44 lines (38 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Recursive Bubble Sort
#include<stdio.h>
void recbubsort(int arr[],int n)
{
if(n==1)
return;
int temp;
for (int i = 0; i < n-1; i++)
{
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
recbubsort(arr,n-1);
}
int main()
{
int n;
printf("\nEnter the number of elements: ");
scanf("%d",&n);
int arr[n];
printf("\nEnter the elements: ");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
recbubsort(arr,n);
printf("\nAfter Sorting Elements are: ");
for (int i = 0; i < n; i++)
{
printf("%d ",arr[i]);
}
printf("\n");
return 0;
}