Quick sort in C error occured when large dataset

-1

i have following swap function;

void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

and i have quicksort function; i created an array with 4000 integers as following

int i;
    int arr[4000];

    clock_t cas;

    for (i = 0; i < 4000; i++) {
        arr[i] = 4000 - i;
    }
    cas = clock();
    int n = sizeof(arr) / sizeof(arr[0]);
    quickSort(arr, 0, n - 1);
    cas = clock() - cas;
    printf("\nC Sort took %f seconds.\n", (double)cas / CLOCKS_PER_SEC);

Above functions work very well. But when i change the dataset number 4000 to 5000 error occuared in swap function. Here is exception error;

The thread 0xc81c has exited with code 0 (0x0).
Exception thrown at 0x00AF1C09 in AssemblyProject.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00402F7C).
Unhandled exception at 0x00AF1C09 in AssemblyProject.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00402F7C).

I don't understand why exception throw when increase the array size to 5000. When i decrese the array under the 4000 it's work.

c
asked on Stack Overflow Jun 23, 2020 by Cemal

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0