Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

I need help with this C assignment, I've been stuck on!!
I have attached the assignment.
It declares that the files merge.c, mergesort.h, and wrt.c CANNOT be changed
Please follow the assignment to further complete all else thats required!

Merge.c [Don't make changes]

#include "mergesort.h"

void merge(int a[], int b[], int c[], int m, int n)
{
   int   i = 0, j = 0, k = 0;

/* Loop through both arrays and compare their elements to eachother */

   while (i < m && j < n)
      if (a[i] < b[j])
         c[k++] = a[i++];
      else
         c[k++] = b[j++];

/* If there are any remaining elements in array b[]. copy them to array c[]. */
   while (i < m)                /* pick up any remainder */
         c[k++] = a[i++];
/* If there are any remaining elements in array a[], copy them to array c[]. */

   while (j < n)
      c[k++] = b[j++];
}

Mergesort.h[Don't make changes]

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

// This function merges two sorted arrys a and b into a sorted array c.
// paterameters: a - c sorts its array. m: is the elements in a n: is the number of elements in b
void    merge(int a[], int b[], int c[], int m, int n);

//This function sorts an array of integers using the merge sort algorithm
//key: the array of integers to be sorted
//n: the number of elements in the array
void    mergesort(int key[], int n);

//This function writes an array of integers
//key: the array of integers to be written
//sz: the number of elements in the array
void    wrt(int key [], int sz);


Wrt.c [Don't make changes]

#include "mergesort.h"

/* Print out the elements of an array of integers.
   key: the array to be printed.
   sz: the number of elements in the array. */

void wrt(int key[], int sz)
{
  int   i;

  for (i=0; i < sz; ++i)
   printf("%4d%s", key[i], ((i < sz - 1)? "" : "\n"));
}

[KINDLY, PLEASE Check the makefile, sort158a.c and merge.c if it needs change, please do so, make sure that the file will execute the "make" command and NO ERRORS DISPLAY]
Ex. 

sort158a.c

#include "mergesort.h"

int main(void)
{
 int sz, key[] = { 4, 3, 1, 67, 55, 8, 0, 4,
                  -5, 37, 7, 4, 2, 9, 1, -1 };

sz = sizeof(key) / sizeof(int); /* the size of key[] */
wrt(key, sz); /* Print the contents of the orginal arry */
mergesort(key, sz); /* Sort the array using mergesort */
printf("After mergesort:"\n); /*prints "After mergesort:"*/
wrt(key, sz); // Print the contents of the sorted array
return 0;
}

MERGE.C
#include "mergesort.h"

void merge(int a[], int b[], int c[], int m, int n)
{
   int   i = 0, j = 0, k = 0;

/* Loop through both arrays and compare their elements to eachother */

   while (i < m && j < n)
      if (a[i] < b[j])
         c[k++] = a[i++];
      else
         c[k++] = b[j++];

/* If there are any remaining elements in array b[]. copy them to array c[]. */
   while (i < m)                /* pick up any remainder */
         c[k++] = a[i++];
/* If there are any remaining elements in array a[], copy them to array c[]. */

  while (i < m)                /* pick up any remainder */
         c[k++] = a[i++];

   while (j < n)
      c[k++] = b[j++];
}


MAKEFILE 

sort158: main.o merge.o mergesort.o wrt.o
        gcc -o sort158 main.o merge.o mergesort.o wrt.o -lm

main.o: main.c mergesort.h
        gcc -c main.c

merge.o: merge.c mergesort.h
        gcc -c merge.c

mergesort.o: mergesort.c mergesort.h
        gcc -c mergesort.c

wrt.o: wrt.c
        gcc -c wrt.c

clean:
        rm *.o sort158

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education