12,401,324 members (39,911 online)
Rate this:
See more:
Below is my code for a mini project, I would like to know how to do an ascending sort to sort total_day_wind in ascending order.

```cout << "Please enter a specific value : ";
cin >> wind_value;

for(i=0; i<dataSize; i++)
{
if(data[i].date().day() != currentDay)
{
total_day_wind /= ave_day_data;
if (wind_value <= total_day_wind)

cout << "Average WindSpeed equal or above " << wind_value << " at Month " << data[i].date().month() << " on Day " << data[i].date().day()  << " is " << total_day_wind << " knots " << endl;
currentDay = data[i].date().day();
total_day_wind = 0.0;
ave_day_data = 0;
}
total_day_wind += data[i].windspeed();
ave_day_data++;
}
system("pause");
total_day_wind = 0.0;
ave_day_data = 0;
```
Posted 16-Jun-10 6:00am
Updated 16-Jun-10 6:03am
Moak11.5K
v2

Rate this:

Solution 2

`total_day_wind` looks like either a `float` or `double` to me. It's a bit trivial to sort a single value...

If you've got a collection of wind speeds somewhere and you want to sort them into ascending order then use std::sort:

```std::vector<double> wind_speeds;

// Much clever code to populate wind_speeds

std::sort( wind_speeds.begin(), wind_speeds.end() );
```

Cheers,

Ash

Edited as yet again I forgot to escape angle brackets
v2
valtron78 16-Jun-10 22:40pm

Does it mean I do a sort first before I start counting the total?
Aescleal 17-Jun-10 5:47am

Does it matter? I have no idea what your code's trying to achieve so I'm afraid I can't answer that question.
Rate this:

Solution 1

The typical way to do this is by using the C++ runtime qsort function.

Another quickie way is to populate a hidden, sorted listbox (the item data is the index into your array). After all data strings have been added, you have a sorted list.
Aescleal 16-Jun-10 14:40pm

Reason for my vote of 1
Yeuch. If you're using C you don't touch qsort with a bargepole. std::sort will give at least as good performance as qsort and is usually better (std::sort can inline the comparison which in qsort has to be through a function pointer).

Top Experts
Last 24hrsThis month
 OriginalGriff 300 Karthik Bangalore 170 ppolymorphe 155 Richard Deeming 130 0x01AA 90
 OriginalGriff 6,963 ppolymorphe 2,950 Karthik Bangalore 2,737 F-ES Sitecore 2,082 Richard MacCutchan 2,077