-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathrecursion3.cpp
59 lines (49 loc) · 985 Bytes
/
recursion3.cpp
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
#include <bits/stdc++.h>
using namespace std;
void mergeSort(int a[],int si,int ei)
{
if(si>=ei){
return;
}
int mid = (si+ei)/2;
mergeSort(a,si,mid);
mergeSort(a,mid+1,ei);
int outarr[ei+1];
int i=0,j=mid,oi=0;
while(i<=mid && j<= ei){
if(a[i]<a[j]){
outarr[oi]=a[i];
i++;
j++;
oi++;
}
else{
outarr[oi]=a[j];
oi++;
j++;
}
}
while(i<=mid){
outarr[oi]=a[i];
oi++;
i++;
}
while(j<=ei){
outarr[oi]=a[j];
j++;
oi++;
}
for(int i=0;i<=ei;i++){
a[i]=outarr[i];
}
}
int main() {
// Write C++ code here
cout<<"---------program started---------"<<endl;
int a[]={4,8,4,6,5,12,25};
mergeSort(a,0,6);
for(int i=0;i<7;i++){
cout<<a[i]<<" ";
}
return 0;
}