Not able to find error < Merge Sort >

#include

using namespace std;

void Merge(int A[], int start, int end)
{
int mid= (start+end)/2;
int i=start;
int j=mid+1;
int k=start;

int temp[100];

while (i<=mid && j<=end)
{
    if (A[i]<A[j])
    {
        temp[k++]=A[i++];
    }
    else
    {
        temp[k++]=A[j++];
    }
}
while(i<=mid)
{
    temp[k++]=A[i++];
}    
while(j<=end)
{
    temp[k++]=A[j++];
}
for (int c = start; c <=end; c++)
{
    A[c]=temp[c];
}

}

void MergeSort(int A[],int start, int end)
{
if (start>=end)
{
return;
}

int mid= (start + end)/2;

MergeSort(A,start,mid);
MergeSort(A,mid+1,end);
Merge(A,start,end);

}

int main()
{
int n;
cin>>n;

int Array[n];
for (int i = 0; i < n; i++)
{
    cin>>Array[i];
}

MergeSort(Array,0,n-1);

for (int i = 0; i < n; i++)
{
    cout<<Array[i]<<" ";
}

}

Hello @rprahulpal03 please share your code by saving it on ide.codingblocks.com

Hello @rprahulpal03 i have corrected your code and it is passing all the test cases:


if you have any doubt you can ask here:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.