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

MergeSort C++ Program Help Input file link: https://www.dropbox.com/s/49azukky67

ID: 668373 • Letter: M

Question

MergeSort C++ Program Help

Input file link: https://www.dropbox.com/s/49azukky67vgb4c/pop_density.txt?dl=0

Final output of the program should look like this:

MergeSort program and clock clicks Program Information: company executives would like to start their expansion by placing locations in the most densely d areas first. To assist them, you have been asked to produce a list of Census Tracts ordered by n density. You have been given a list of the approximately 74,000 Census Tracts in the United States. The name, area (in square kilometers), total population, and population density (in people per square kilometer) are given to you for each tract. Input File Format Each record of the input file is on a separate line. Each line contains (in this order) a name (string), an area in square kilometers (double), a population count (int), and a population density (double). A pipe (I) is used to separate the different attributes of each record. Below are three example records from the input file: Census Tract 201, Autauga County, Alabama 19.84473419420788118081183.651479494869 Census Tract 202, Autauga County, Alabama | 3.34583234555866123551703.860730836106 Census Tract 203, Autauga County, Alabama15.35750339330735130571570.60159846447

Explanation / Answer

Mergesort Program:

This C++ program, implements the merge sort model of sorting elements.

               Here is the source code of the C++ program which takes the values of array as input and returns the sorted array as output. This C++ program is successfully compiled and run on DevCpp, a C++ compiler.

    #include<stdio.h>

     #include<conio.h>

    #include <iostream>

    using namespace std;

    void merge(int *,int, int , int );

    void mergesort(int *a, int low, int high)

    {

        int mid;

        if (low < high)

        {

            mid=(low+high)/2;

            mergesort(a,low,mid);

            mergesort(a,mid+1,high);

            merge(a,low,high,mid);

        }

        return;

    }

    void merge(int *a, int low, int high, int mid)

    {

        int i, j, k, c[50];

        i = low;

        k = low;

        j = mid + 1;

        while (i <= mid && j <= high)

        {

            if (a[i] < a[j])

            {

                c[k] = a[i];

                k++;

                i++;

            }

            else

            {

                c[k] = a[j];

                k++;

                j++;

            }

        }

        while (i <= mid)

        {

            c[k] = a[i];

            k++;

            i++;

        }

        while (j <= high)

        {

            c[k] = a[j];

            k++;

            j++;

        }

        for (i = low; i < k; i++)

        {

            a[i] = c[i];

        }

    }

    int main()

    {

        int a[20], i, b[20];

        cout<<"enter the elements ";

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

        {

            cin>>a[i];

        }

        mergesort(a, 0, 4);

        cout<<"sorted array ";

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

        {

            cout<<a[i];

        }

        cout<<"enter the elements ";

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

        {

            cin>>b[i];

        }

        mergesort(b, 0, 4);

        cout<<"sorted array ";

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

        {

            cout<<b[i];

        }

        getch();

    }