영휘 0 Newbie Poster
#include <stdio.h>

void Merge(int *, int, int, int);


void MergeSort(int *array, int left, int right)
{
    int mid = (left + right) / 2;

    if (left < right)
    {
        MergeSort(array, left, mid);
        MergeSort(array, mid + 1, right);
        Merge(array, left, mid, right);

    }
}

void Merge(int *array, int left, int mid, int right)
{
    int tempArray[50000];

    int pos = 0, lpos = left, rpos = mid + 1;
    while (lpos <= mid && rpos <= right)
    {
        if (array[lpos] < array[rpos])
        {
            tempArray[pos++] = array[lpos++];
        }
        else
        {
            tempArray[pos++] = array[rpos++];
        }
    }
    while (lpos <= mid) tempArray[pos++] = array[lpos++];
    while (lpos <= right) tempArray[pos++] = array[rpos++];
    int iter;
    for (iter = 0; iter < pos; iter++)
    {
        array[iter + left] = tempArray[iter];
    }
    return;
}
int main()
{

    const int number_of_elements= 50000;
    int array[50000];

    int iter;
    for (iter = 0; iter < number_of_elements; iter++)
    {

        array[iter] = rand() % 50000;
    }

    MergeSort(array, 0, number_of_elements - 1);
    for (iter = 0; iter < number_of_elements; iter++)

    {
        printf("%d", array[iter]);
    }

    return 0;
}

What's the problem?