PDA

View Full Version : What is the best way to sort an array of doubles in ascending order using c++?


buckboard
May 9, 2012, 03:01 AM
Hi,
Ive got an array filled with about 2000 different doubles. These are read in from an external .txt. I now want to calculate the median of these numbers. For this I have to sort the array in ascending order. My first attempt was std::sort


for (I=1; I<2002; I++)
{
datenSatz>>zahl;
daten[i]=zahl;
std::sort(daten, daten+2002);
cout<<daten[i]<<endl;
berechnungen<<daten[i]<<endl;

}

and then printing it in a .txt. This works fine, just that the result is pure bogus. It sorts numbers allright, just not mine. Not too sure what it actually does with it.

Any help?