forked from akkupy/codeDump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecursive.c
107 lines (47 loc) · 996 Bytes
/
Recursive.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<stdio.h>
void simplemerge(int x[] , int l , int s , int r )
{
int temp[30], k=0, i=l, j=s ;
while(i<s && j<=r)
{
if(x[i]<x[j])
temp[k++]=x[i++];
else
temp[k++]=x[j++];
}
while(i<s)
temp[k++]=x[i++];
while(j<=r)
temp[k++]=x[j++];
for(i=l, j=0; j<k; )
x[i++]=temp[j++];
}
void mergesort(int a[] , int l , int r)
{
int m;
if(l<r)
{
m=(l+r)/2;
mergesort(a,l,m);
mergesort(a,(m+1),r);
simplemerge(a, l , (m+1), r);
}
}
void main()
{
int a[50], n , i ;
printf("Enter the no of elements: ");
scanf("%d",&n);
printf("Enter the elements : \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
mergesort(a,0,(n-1));
printf(" sorted array is : ");
for(i=0;i<n;i++){
printf("%d",a[i]);
if(i!=n-1)
printf(" , ");
}
}