如何使用 std::sort 根据某个函数返回的值对数组进行排序,同时传递要排序的数组元素?
class Board{
//members
};
int score(int num,Board b){
return b.evaluate(num);
//lets say score() function returns an evaluation based
//on num and Board type object b.
}
void main(){
Board b;
int num_array[10]{0,1,2,3,4,5,6,7,8,9};
std::sort(num_array.begin(),num_array.end());
//how to use std::sort to sort num_array based on values returned
//by score() while passed elements of num_array
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将函数作为 std::sort 中的第三个参数传递,还是需要以其他方式解决?