I looked for C++ examples of Merge sort shown below. When I tried to compile it I get errors about two temporary arrays L[n1], R[n2]
. I've read that an array should have fixed size, if not, we make it dynamic int* tab = new int[n1]
for instance. But I've seen many examples like this below everywhere, so why this code below is working for other people?
int Merge(int A[],int p, int q,int r)
{
int n1,n2,i,j,k;
n1=q-p+1;
n2=r-q;
int L[n1],R[n2];
for(i=0;i<n1;i++)
{
L[i]=A[p+i];
}
...