I will start by giving the code:
CODE
double* tmpArray = new double[(INDEX_MAX / BLOCKS)];
for(int i = 0; i < BLOCKS; i++)
{
for(int k = 0; k < (INDEX_MAX / BLOCKS); k++)
{
tmpArray[k] = anArray[count];
count++;
}
int elements = sizeof(tmpArray) / sizeof(tmpArray[0]);
sort(tmpArray, tmpArray + elements);
int whatever = 1;
for(int j = 0; j < (R+1); j++)
{
topArray[place] = tmpArray[(INDEX_MAX / BLOCKS) - whatever];
place++;
whatever++;
}
whatever = 1;
for(int z = 0; z < (INDEX_MAX / BLOCKS); z++)
{
tmpArray[z] = 0; // just zeroing out tmpArray before deleting it
}
}
delete[] tmpArray;
It's not clean, but its a very small project and gets the job done. Well, not yet but it will, using OS X and X-Code to compile the code (without tmpArray being pointer based) the sort() function works fine to sort the array. However, the values INDEX_MAX and BLOCKS are defined when the program starts by using a cin, and Windows does not allow for allocation of arrays after compile time unless it is a pointer based array, so I was forced to switch tmpArray to pointer based.
By doing that, the sort() function broke, and no longer works. I completely blanked on how to sort tmpArray from greatest to least (contains randomly generated numbers between 0.00001 and 1). Could anyone possibly help me out on sorting the pointer based array in descending order. Again, I seem to have blanked.
Thanks in advance!