如何根据数组元素对struct数组进行排序?

时间:2017-03-12 13:43:05

标签: c++ arrays sorting struct

我有一个如下所示的结构数组:

struct P {
    vector<double> All_w;
    double w = 0;
    double sum_w = 0;
};

P array[10];

我想根据All_w对数组[10]进行排序。例如;

for (int i = 0; i < T; i++){
    sort(array.begin(), array.end(), [](const P &Pr, const P &Ps, const int &t) { return Pr.All_w[T] < Ps.All_w[T]; });
}

我不知道是否有可能或有其他替代方式。

0 个答案:

没有答案
相关问题