is_sorted(): This function is available in the file stl_algo.h. This function determines whether the elements of a sequence are sorted. This function returns true if the elements are sorted, false otherwise.
Parameters: Two parameters are required for this function.
__first – An iterator.
__last – Another iterator.
Syntax:
is_sorted(__first, __last)
For Example:
arr = {1,4,6,8,10}
is_sorted(arr.begin(), arr.end()) = > It return true (1) because the given sequence is sorted.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> arr = {1, 4, 6, 8, 10};cout << is_sorted(arr.begin(), arr.end()) << "\n";return 0;}
No comments:
Post a Comment