Which one should I use to sort vectors in descending order?

Asked 2 years ago, Updated 2 years ago, 153 views

Please explain which one to use when sorting vectors in descending order, which one do you prefer?

std::sort(numbers.begin(), numbers.end(), std::greater<int>());
std::sort(numbers.rbegin(), numbers.rend());

c++ iteration sorting stl vector

2022-09-22 16:55

1 Answers

The first code better reveals the developer's "intention."

std::sort(numbers.begin(), numbers.end(), std::greater<int>());


2022-09-22 16:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.