Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

How do I fix the error Conflicting types for 'mergesort' for this function: void mergesort(float a[], float temp[], int l, int r) { taken from

How do I fix the error "Conflicting types for 'mergesort'" for this function: void mergesort(float a[], float temp[], int l, int r) {

taken from code below:

#define _CRT_SECURE_NO_DEPRECATE

#include

void merge(float a[], float temp[], int l, int m, int r) {

int temp_pos = l, size = r - l + 1, left_end = m - 1, i;

while (l <= left_end && m <= r) {

if (a[l]

else temp[temp_pos++] = a[m++];

}

while (l <= left_end)temp[temp_pos++] = a[l++];

while (m <= r)temp[temp_pos++] = a[m++];

for (i = 0; i

a[r] = temp[r];

r--;

}

}

void insertionsort(float a[], int l, int h) {

int i;

for (i = l; i <= h; i++) {

int j = i - 1, val = a[i];

while (j >= 0 && a[j]>val) {

a[j + 1] = a[j];

j--;

}

a[++j] = val;

}

}

void mergesort(float a[], float temp[], int l, int r) {

if (r - l>8) {

int mid = l + (r - l) / 2;

mergesort(a, temp, l, mid);

mergesort(a, temp, mid + 1, r);

merge(a, temp, l, mid + 1, r);

}

else {

insertionsort(a, l, r);

}

}

int main() {

//CHEGGEA, declare file poiters for reading and writing to file

FILE *fp1, *fp2;

float arr[10], temp[10];

printf("Enter element of array ");

int i;

//CHEGGEA, open input file for reading, output file for writing

fp1 = fopen("data1.txt", "r");

//check if file is open

if (!fp1)

{

printf("Not able to open input file data1.txt ");

return -1;

}

//file open successful , now you can read file and fill up the array.,CHEGGEA, as a generailsed form

for (i = 0; i<10; i++) {

temp[i] = 0;

fscanf(fp1, "%f", &arr[i]);

//scanf("%f", &arr[i]);

}

//open file for writinhg to file out1.,CHEGGEA

fp2 = fopen("out1.txt", "w");

if (!fp2)

{

printf("Not able to open file out1.txt for writinng ");

return -1;

}

//replace all print with frpintf to write to a file called out1.txt,CHEGGEA

fprintf(fp2,"%s"," your array : ");

for (i = 0; i<10; i++)

fprintf(fp2,"%.2f ", arr[i]);

mergesort(arr, temp, 0, 9);

fprintf(fp2,"%s"," your sorted array : ");

for (i = 0; i < 10; i++)

//commented out below line to write to file called out1.txt

//printf("%.2f ", arr[i]);

fprintf(fp2, "%.2f ", arr[i]);

fclose(fp1);

fclose(fp2);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students explore these related Databases questions

Question

What are OLAP Cubes?

Answered: 3 weeks ago