在下面的共享代码链接中,基于对的第一个元素以降序对向量元素进行了排序,但看起来好像没有发生排序并且没有收到预期的输出。这里第一个迭代值需要以降序打印订购和以下相同代码在iterateVector()函数中编写。
sort(vect.begin(),vect.end(),[] (const pair<double,double> &a,
const pair<double,double> &b){return (a.first > b.first);});
http://coliru.stacked-crooked.com/a/d868271155375b17
实际输出:
first iterative value =30 second iterative value=300
first iterative value =45.3 second iterative value=300
first iterative value =23 second iterative value=301
first iterative value =175 second iterative value=303
预期输出:
first iterative value =175 second iterative value=303
first iterative value =45.3 second iterative value=300
first iterative value =30 second iterative value=300
first iterative value =23 second iterative value=301