Quiz vector STL

We wish to sort these integers but we must remember what their orignal indices were before sorting.

We cannot achieve this with the inbuilt sort function.

We may build a vector> data where data[i].first = AR[i] and data[i].second = i and sort this vector using sort(data.begin(), data.end()).

We may build a vector> data where data[i].first = i and data[i].second = AR[i] and sort this vector using sort(data.begin(), data.end()).

This cannot be achieved without a custom comparator and two arrays.

How can we acheive it

hello @mohitsharmakosi2001

this one will work fine.

u store each element as pair. where first value of pair is element value and second is index.
and then we can direcly sort it without using any comparator (element will sorted in ascending order of first value of pair).

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.