
Write gm_qsort, your own qsort, with the signature the C standard gives qsort: order the nmemb elements of size bytes stored at base, comparing any two of them with cmp, and move whole elements byte by byte because size is only known at run time.
int v[] = {4, 1, 7, 3}; gm_qsort(v, 4, sizeof(int), cmp_int_asc);Expected result
1 3 4 7For your own tracking. Tests grade your code.
struct rec v[] = {{30, 3, 300}, {10, 1, 100}, {20, 2, 200}}; gm_qsort(v, 3, sizeof(struct rec), cmp_rec_key); // printed as key:serial:weightExpected result
10:1:100 20:2:200 30:3:300char v[][3] = {"zz", "ab", "mm"}; gm_qsort(v, 3, 3, cmp_tag_head);Expected result
ab mm zzchar v[] = {'g', 'a', 'z', 'm'}; gm_qsort(v, 4, sizeof(char), cmp_char_asc); // printed with no separatorExpected result
agmzstruct rec v[] = {{5, 1, 0}, {5, 2, 0}, {5, 3, 0}}; gm_qsort(v, 3, sizeof(struct rec), cmp_rec_key); // keys, then the serial totalExpected result
5 5 5
sum=6int v[3] = {9, 8, 7}; gm_qsort(v, 0, sizeof(int), cmp_int_asc);Expected result
9 8 7Expected files
qsort.cAllowed functions
None. Write every helper yourself.
Allowed headers
Standard C library
Implements the contract of a function from the standard C library.

v0.40: Create exercises. Challenge the community.
Meet Studio →Write gm_qsort, your own qsort, with the signature the C standard gives qsort: order the nmemb elements of size bytes stored at base, comparing any two of them with cmp, and move whole elements byte by byte because size is only known at run time.
int v[] = {4, 1, 7, 3}; gm_qsort(v, 4, sizeof(int), cmp_int_asc);Expected result
1 3 4 7For your own tracking. Tests grade your code.
struct rec v[] = {{30, 3, 300}, {10, 1, 100}, {20, 2, 200}}; gm_qsort(v, 3, sizeof(struct rec), cmp_rec_key); // printed as key:serial:weightExpected result
10:1:100 20:2:200 30:3:300char v[][3] = {"zz", "ab", "mm"}; gm_qsort(v, 3, 3, cmp_tag_head);Expected result
ab mm zzchar v[] = {'g', 'a', 'z', 'm'}; gm_qsort(v, 4, sizeof(char), cmp_char_asc); // printed with no separatorExpected result
agmzstruct rec v[] = {{5, 1, 0}, {5, 2, 0}, {5, 3, 0}}; gm_qsort(v, 3, sizeof(struct rec), cmp_rec_key); // keys, then the serial totalExpected result
5 5 5
sum=6int v[3] = {9, 8, 7}; gm_qsort(v, 0, sizeof(int), cmp_int_asc);Expected result
9 8 7Expected files
qsort.cAllowed functions
None. Write every helper yourself.
Allowed headers
Standard C library
Implements the contract of a function from the standard C library.

Run the tests to grade your code
Build your code, then check each test here. Open a result to inspect its output.