samedi 28 décembre 2019

Descending order sorting on basis of first element in vector of pair is not giving desired results

In below shared code link ,Sorting the vector elements on the basis of first element of pairs in descending order is performed but it looks like sorting is not happening and expected output is not received.Here first iterative value needs to be printed in descending order and for the same below code is written in iterateVector() function.

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

Actual output:

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

Expected output:

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

Aucun commentaire:

Enregistrer un commentaire