By Sergey Skudaev
Recursive Binary Merge Sort, implementation in C++
Date:3/26/2000
#include <iostream>
#include <toolhelp.h>
//GetTickCount() is valid only for Borland C++
void printArray ( int
array [], int last );
void recursive_bin_merge ( int
array [], int last, int &cells
);
void resetArray(int array[], int
last);
void merge(int array[],
int listUp[], int
listDn[], int index, int
cells,
int idxUp, int
idxDn);
intmain(int argc, char* argv[])
{
int array[] = {75, 55, 15, 20, 85, 30, 35, 10, 60, 40, 50, 25, 45, 80, 70,
65};
int last = 16;
int cells = 1;
long lstart= 0;
long lend = 0;
printArray ( array, last );
lstart = GetTickCount( );
recursive_bin_merge ( array, last, cells);
lend = GetTickCount();
int takes;
takes = lend - lstart;
cout<<"\nIt takes "<<takes<<" msec to sort the array of 16 integers"<<endl;
int hold = 1;
cin >> hold;
int idxUp, int idxDn)
{
while ((idxUp < cells)&&(idxDn < cells))
{
if
( listUp [idxUp] < listDn [idxDn] )
{
array [index] =
listUp [idxUp];
index++;
idxUp++;
}
else
{
array [index] =
listDn [idxDn];
index++;
idxDn++;
}
}
while
(idxUp < cells)
{
array [index] = listUp [idxUp];
index++;
idxUp++;
}
while
(idxDn < cells)
{
array [index] = listDn [idxDn];
index++;
idxDn++;
}
}