Hey everyone. Im having some problems with mergesort. Im supposed to run the mergesort function then print to a file. It's not printing.. Can someone show me where im going wrong?
This is the part of my switch statement that calls mergesort
case 3:
//Sort array using Mergesort
mergeSort( data, 1, MAXSIZE );
//Print to outfile "lab07_mergesort.txt"
printArray( data, MAXSIZE );
//Inform user of successful mergesort
cout << "The data has been sorted using Mergesort and" << endl;
cout << "printed to file lab7_mergeout.txt." << endl;
break;
and these are my functions:
//Function printArray
void printArray( float array[], int SIZE )
{
for( int i = 0; i < SIZE; ++i )
bubbleoutfile << array[i] << " " ;
}
//Function mergeSort
void mergeSort(float array[], int start, int end)
{
int n = end - start + 1;
if (n > 1)
{
int n1 = n / 2;
mergeSort(array, start, start + n1 - 1);
mergeSort(array, start + n1, end);
float *tmp = new float[ end - start + 1 ];
float *dest = tmp,
*src1 = array + start,
*src2 = array + start + n1;
while ((src1 < array + start + n1) && (src2 <= array + end))
{
if (*src1 <= *src2)
*dest++ = *src1++;
else
*dest++ = *src2++;
}
while (src1 < array + start + n1 )
*dest++ = *src1++;
while (src2 <= array + end)
*dest++ = *src2++;
memcpy( array + start, tmp, n*sizeof(int) );
delete[] tmp;
}
}
Thanks in advance.