Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to check if vector is ordered c++

#include <vector> // vector 
#include <algorithm> // is_sorted
#include <iostream> // cout 
using namespace std;
int main()
{
    vector<int> a = {6,5,3,5,7,8,5,2,1};
    vector<int> b = {1,2,3,4,5,6,7,8,9};
    
    if(is_sorted(a.begin(), a.end()))
        cout << "a is sorted
";
    else
        cout << "a is not sorted
";
    
    if(is_sorted(b.begin(), b.end()))
        cout << "b is sorted
";
    else
        cout << "b is not sorted
";
}
 
PREVIOUS NEXT
Tagged: #check #vector #ordered
ADD COMMENT
Topic
Name
5+5 =