MERGERSORT challenge

#include
using namespace std;
void merge(int *a,int s,int e)
{
int mid=(s+e/2);
int i=s;
int j=mid+1;
int k=s;
int temp[100000];
while(i<=mid and j<=e)
{
if(a[i]<a[j])
{
temp[k++]=a[i++];
}
else
{
temp[k++]=a[j++];
}
}
while(i<=mid)
{
temp[k++]=a[i++];
}
while(j<=e)
{
temp[k++]=a[j++];
}
for(int i=s;i<=e;i++)
{
a[i]=temp[i];
}
return;
}
void merge_sort(int a[],int s,int e)
{
if(s>=e)
{
return;
}
//divide
int mid=(s+e)/2;
merge_sort(a,s,mid);
merge_sort(a,mid+1,e);
//merge
merge(a,s,e);
}
int main()
{
int a[100000];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
merge_sort(a,0,n-1);
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
what is the problem in this code.

@Abhishmu5 please share the code using cb ide

@Abhishmu5 brackets missing and increased the size


dont forget to hit like and mark resolved if cleared :smiley:

please tell me the difference in a[n] and a[1000].

@Abhishmu5 its same but when we write a[n] it means we are assigning the req amount of memory only ,(you can change it to 1000005 too if you want)

sir, it is not working if i am using a[100000] it is giving me a run time error.

@Abhishmu5 use 1 more 0

yes, it is working properly now.thank u sir.

@Abhishmu5 np just mark it resolved :smiley: