There are many reasons due to which your code would not work correctly.
I have done the modifications in your code as follow:
-
TLE
[you have to start inserting from the s index but you are doing it from the 0th index.]
for( int i=s;i<=e;i++)
{
arr[i] = temp[i-s];
}
-
Run time error
[ the values of e and s can be other than n-1 and 0 resp. (you were not considering this)]
int mid = (s+e)/2;
int i=s,j=mid+1,k=0;
int n=e-s+1;
int temp[n];
// k should be initialized with 0 as you will insert in it from the starting index
// temp can have more than 100 elements
-
Wrong Output:
[You are printing the output in wrong format]
for(int i = 0;i<n;i++)
{
cout<<arr[i]<<" ";
}
Click here to see the modified code.
Hope, this would help.
Give a like, if you are satisfied.