Turn this into C code.

main(){n will be given as command line argument
struct timespec ts_begin, ts_end;double elapsed;
create array A ( n double values) and randomly generate these values also create arrays B and C with the same size of A Afirsthalf and AsecondHalf with the half size of A//-------------------- ONE THREAD CASE --------------------copy A into B
clock_gettime(CLOCK_MONOTONIC, &ts_begin);
create thB sortThread to sort B /* use selection/insertion sort O(n^2) */join thB
clock_gettime(CLOCK_MONOTONIC, &ts_end); elapsed = ts_end.tv_sec - ts_begin.tv_sec; elapsed += (ts_end.tv_nsec - ts_begin.tv_nsec) / 1000000000.0;
Sorting by ONE thread is done in
elapsed*1000 ms
//-------------------- TWO THREADS CASE --------------------copy A into Afirsthalf and AsecondHalf
clock_gettime(CLOCK_MONOTONIC, &ts_begin);
create thA1 sortThread to sort Afirsthalf /* use selection/insertion sort O((n/2)^2) */create thA2 sortThread to sort Asecondhalf /* use selection/insertion sort O((n/2)^2) */join thA1join thA2create thM mergeThread to merge Afirsthalf and Asecondhalf into C/* make sure this just merges the sorted values form two arrays while keeping them sorted. O(n) *//* dont' copy these arrays and then call sort! which will be like sorting the whole thing! */join thM
clock_gettime(CLOCK_MONOTONIC, &ts_end); elapsed = ts_end.tv_sec - ts_begin.tv_sec; elapsed += (ts_end.tv_nsec - ts_begin.tv_nsec) / 1000000000.0;
Sorting by TWO threads is done in
elapsed*1000 ms
}