如何进行升序排序 [英] How to do an ascending sort
本文介绍了如何进行升序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
:confused:以下是我的迷你项目代码,我想知道如何进行升序排序以对total_day_wind进行升序排序.
: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;
推荐答案
total_day_wind
看起来像float
或double
给我.对单个值进行排序有点琐碎...
如果您在某处收集了风速并且想要将它们按升序排序,请使用std :: sort:
total_day_wind
looks like either afloat
ordouble
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
典型的方法是使用C ++运行时qsort函数.
另一种快捷方式是填充一个隐藏的,已排序的列表框(项目数据是数组的索引).添加所有数据字符串后,您将获得一个排序列表.
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.
这篇关于如何进行升序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文