I don't know what is the problem with my code please help.
it's a merge sort code.
#include<bits/stdc++.h>
using namespace std;
void MergeSort(int l, int r);
void Merge(int l1,int r1,int l2,int r2);
int a[100000];
int main ()
{
int n;cin >> n;
for(int i=0;i<n;++i)cin >> a[i];
MergeSort(0,n-1);
for(int i=0;i<n;++i)cout << a[i] << endl;
}
void MergeSort(int l, int r){
if(l<=r){
return;
}
int m=(l+r)/2;
MergeSort(l,m);
MergeSort(m+1,r);
Merge(l,m,m+1,r);
}
int n[1010];
void Merge(int l1,int r1,int l2,int r2){
int ind=0;int f1=l1;
while(l1<=r1 && l2<=r2){
if(a[l1]>=a[l2]){
n[ind]=a[l1];++l1;
}
else{
n[ind]=a[l2];++l2;
}
++ind;
}
while(l1<=r1){
n[ind]=a[l1];++l1;++ind;
}
while(l2<=r2){
n[ind]=a[l2];++l2;++ind;
}
for(int i=f1;i<=r2;++i){
a[i]=n[i-f1];
}
}
So I give this to my application for a test case: 1 6 7 4 2
And my programm give me this:
1
6
7
4
2
the same thing as I give the programme please Help!