13,086,120 members (84,449 online)
Rate this:
See more:
:confused: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.6K
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).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Graeme_Grant 170 OriginalGriff 138 Jochen Arndt 115 Kornfeld Eliyahu Peter 90 BillWoodruff 80
 OriginalGriff 3,095 Graeme_Grant 1,519 ProgramFOX 1,367 ppolymorphe 1,217 Jochen Arndt 1,205

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 16 Jun 2010