Question: example code: /* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using

 example code: /* * * after splitting this file into the

example code:

/* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR | MERG) *.c * */ /* * * srt.h file * */ #ifndef SRT_H #define SRT_H #include  #define MAX_BUF 256 #define swap(qx,qy,sz) \ do { \ char buf[MAX_BUF]; \ char *q1 = qx; \ char *q2 = qy; \ for (size_t m, ms = sz; ms > 0; ms -= m, q1 += m, q2 += m) { \ m = ms  #include  #include  #include "srt.h" static int compare(const void *, const void *); int main(int argc, char *argv[]) { int nelem = argc == 2 ? atoi(argv[1]) : SHRT_MAX; TYPE *a = calloc(nelem, sizeof(TYPE)); #ifdef RAND for (int i = 0; i  a[i + 1]) { printf("fail "); goto end; } } printf("pass "); #endif end: free(a); return 0; } static int compare(const void *p1, const void *p2) { if (*(TYPE *)p1  *(TYPE *)p2) { return +5; } return 0; } /* * * srtbubb.c file * */ #include  #include  #include "srt.h" void srtbubb(void *base, size_t nelem, size_t size, int (*compar)(const void *, const void *)) { for (size_t i = nelem - 1; i > 0; --i) { bool sorted = true; for (size_t j = 0; j  0) { swap(qj, qn, size); sorted = false; } } if (sorted) { break; } } return; } /* * * srtinsr.c file * */ #include  #include  #include "srt.h" void srtinsr(void *base, size_t nelem, size_t size, int (*compar)(const void *, const void *)) { char buf[size], *qb = base; for (size_t i = 1; i  0 && compar(buf, qb + size * (j - 1))  #include  #include "srt.h" void srtmerg(void *base, size_t nelem, size_t size, int (*compar)(const void *, const void *)) { char *qb = base, *ql, *qr, *qt; size_t i, j, l, r; if (nelem  0) { swap(qb, qb + size, size); } return; } l = nelem / 2; r = nelem - l; ql = qt = malloc(size * l); memcpy(ql, qb, size * l); qr = qb + size * l; srtmerg(ql, l, size, compar); srtmerg(qr, r, size, compar); i = 0; j = l; while(i   Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided. Submit a single C file called "srtheap.c" only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!