Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views1 page

Merge Sort

The document contains a C++ implementation of the merge sort algorithm. It includes functions for merging sorted arrays and recursively sorting them. The main function prompts the user to enter elements for sorting but is incomplete.

Uploaded by

anon_486796284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Merge Sort

The document contains a C++ implementation of the merge sort algorithm. It includes functions for merging sorted arrays and recursively sorting them. The main function prompts the user to enter elements for sorting but is incomplete.

Uploaded by

anon_486796284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;


#include <conio.h>
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\n";

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

cin>>a[i];

You might also like