#include <stdio.h>
void merge_sort(int [], int, int);
void merge_array(int [], int, int, int);
main()
{
int a[50], n, i;
printf("\nEnter size of an array: ");
scanf("%d", &n);
printf("\nEnter elements of an array:\n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
merge_sort(a, 0, n-1);
printf("\n\nAfter sorting:\n");
for(i=0; i<n; i++)
printf("\n%d", a[i]);
getch();
}
void merge_sort(int a[], int beg, int end)
{
int mid;
if (beg < end)
{
mid = (beg+end)/2;
merge_sort(a, beg, mid);
merge_sort(a, mid+1, end);
merge_array(a, beg, mid, end);
}
}www.eazynotes.com Gursharan Singh Tatla Page No. 2
void merge_array(int a[], int beg, int mid, int end)
{
int i, left_end, num, temp, j, k, b[50];
for(i=beg; i<=end; i++)
b[i] = a[i];
i = beg;
j = mid+1;
k = beg;
while ((i<=mid) && (j<=end))
{
if (b[i] <= b[j])
{
a[k] = b[i];
i++; k++;
}
else
{
a[k] = b[j];
j++; k++;
}
}
if (i <= mid)
{
while (i <= mid)
{
a[k] = b[i];
i++; k++;
}
}
else
{
while (j <= end)
{
a[k] = b[j];
j++; k++;
}
}
}
types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort
There's only one type of sort in C++; std::sort. If you want other types you'll need to write your own.
The Express edition of C++ does not require a serial code. It is free.
The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector<std::string> vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}
0-black.2-green
Top down merge sort is the easy way of merge sort in C language . It is used to derived o(n log n) algorithm . This is in par with the other methods.
types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort
Sometimes, it is. Some implementations compile C++ code into C code, and then compile the C code.
There's only one type of sort in C++; std::sort. If you want other types you'll need to write your own.
It is used to distinguish between the C or C++
All C++ source code is is a text file with the .cpp extension. So if you save your code as *****.cpp then it is automatically C++ source code.
The Express edition of C++ does not require a serial code. It is free.
yihuy
Code, compile, link, run.
#include <libraryname>
Turbo C compiles c source. turbo c++ compiles c++ source code.
The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector<std::string> vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}