Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I need three files in the following C++ program. i need someone to provid

ID: 3717992 • Letter: H

Question

Hello,

I need three files in the following C++ program. i need someone to provide mergesort.cpp, mergesort_test.cpp and mergesort.h. from following program.

Requested files: Mergesort.h, Mergesort.cpp, Mergesort_test.cpp

#include<iostream>

#include<fstream>

using namespace std;

//here l is left index m is middle r is right index

void mergefunction(int a[], int l, int m, int r)

{

int k;

  

//two temp array and their size

int xs=m - l + 1;//first array size

int ys=r-m;//second array size

  

int X[m - l + 1], Y[r - m];

  

//X is first part and copy data to it and Y is next, data copy to it

for (int i = 0; i < xs; i++)

X[i] = a[l + i];

for (int j = 0; j < ys; j++)

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

  

//merge these array in a[]

int i = 0; // Initial index of X

int j = 0; // Initial index of Y

k = l; // Initial index of a

while (i < xs && j < ys)

{

if (X[i] <= Y[j])

{

a[k] = X[i];

i++;

}

else

{

a[k] = Y[j];

j++;

}

k++;

}

  

  

//if data is left of Y then copy remaining

while (j < ys)

{

a[k] = Y[j];

j++;

k++;

}

//if data is left of X they copy remaining

while (i < xs)

{

a[k] = X[i];

i++;

k++;

}

}

//l is lowest index h is highest index

void mergesort(int a[], int l, int h)

{

if (l < h)

{

//new middle

int m = l+(h-l)/2;

  

// call mergesort for both part

mergesort(a, l, m);

mergesort(a, m+1, h);

//call merge function to merge

mergefunction(a, l, m, h);

}

}

int main()

{

ifstream ofile;

int x,cnt=0;//cnt will tell the number of element in file

int a[100005];

ofile.open ("threesData.bin");

  

while(ofile>>x)

{

a[cnt++]=x;

}

//call mergesort

mergesort(a, 0, cnt - 1);

  

ofstream opfile;//for output file

  

opfile.open("sortedThreesData.bin");

for(int i=0;i<cnt;i++)

opfile<<a[i]<<" ";

opfile.close();

ofile.close();

return 0;

}

Explanation / Answer

}

#include <iostream>
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote