Sorting using inbuilt sort function when we pass some class or struct

Given an array of N integers.

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

Option1: 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()).

Doubt: How the above option is correct, wont sort function need to know whether to sort on basis of first or second. On what basis is it going to sort?

1 Like