Vector Quiz STL 5

Here what is wrong is storing like first as index and second as value at that index, it’s just that we need to sort according to the second element in the pair.

Hey @Sakshi2004 for which question are you talking about? Do refer the question too.

i got the question, the issue with this will be

It will sort on the basis of indexes as indexes as data[i].first = i , so it will give same output as input.

Indexes ->  1 2 3 4 5 6
Value   ->  4 9 1 5 2 4 

So when you will sort them with this method you will get same output as input. That’s why this option won’t be correct.

Yes, I understood that, but I was asking this only that we can make a compare function to sort on the basis of second element, so that should’nt be wrong then?

Yes if you will do it with comparator then no issues with that. It’s just , it was not mention in the question. So we have to answer it accordingly

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.