#include <algorithm> // std::is_sorted
#include <iostream> // std::cout
#include <vector> // std::vector
// ------------------------------------------------------------
// Function: isVectorSorted
// Purpose: Check whether a vector is sorted in non‑decreasing order.
// Notes:
// - Uses std::is_sorted, which runs in O(n) time.
// - std::is_sorted is idiomatic, efficient, and expressive.
// ------------------------------------------------------------
bool isVectorSorted(const std::vector<int>& vec) {
// std::is_sorted returns true if each element is <= the next.
return std::is_sorted(vec.begin(), vec.end());
}
int main() {
std::vector<int> data = {1, 2, 3, 5, 8, 13};
bool sorted = isVectorSorted(data);
std::cout << "Vector is "
<< (sorted ? "sorted" : "NOT sorted")
<< std::endl;
}
/*
run:
Vector is sorted
*/