std::prev_permutation
The function `std::prev_permutation` is part of the C++ Standard Library, specifically included in the `<algorithm>` header. It rearranges the elements in a given range to form the previous lexicographical permutation. If the current arrangement is the first permutation (i.e., sorted in ascending order), it transforms the range into the last permutation (sorted in descending order).
To use `std::prev_permutation`, you provide iterators that define the range of elements to be permuted. The function returns a boolean value: `true` if the permutation was successful and `false` if the input was already the first permutation. This function is useful in algorithms that require exploring permutations in reverse order.