There’s an algorithm for that: std::is_sorted
:
if (std::is_sorted(v.begin(), v.end()) {
return v.back(); // the largest element would be the last one
}
else {
// ??
}
13
solved How can I check if vector elements are in order consecutively?