4 ms·
1. Have an immutable container of Persons named `persons` 2. Have another container named `indices` representing the index or iterator into your Persons contai
by inetknght 3y ago
1. Have an immutable container of Persons named `persons`
2. Have another container named `indices` representing the index or iterator into your Persons container
In C++:
3. `std::sort(begin(indices), end(indices), [&](int lhs, int rhs)->bool{ return persons[lhs].age() < persons[rhs].age(); });`
I don't know Java but I am sure there are many ways to do it in Java.
- misja111 3y agoEh yes, this works, but you are not using Arrays.intSort here. Which means that the optimizations that the article is about won't apply. intSort (or any other of the sorts in the article) works purely on an Array of Ints, moving them around and comparing them to each other. It's quite hard to come up with something that we could use in every day programming that will benefit from the new optimizations.