is_sorted_until() in C++

is_sorted_until(): This function is available in the file stl_algo.h. This function determines the end of a sorted sequence. This function returns an iterator pointing to the last iterator  i in [__first, __last) for which the range [__first, i) is sorted.

Parameters: Two parameters are required for this function.

__first – An iterator.

__last – Another iterator. 

Syntax:

vector<data_type>::iterator it = is_sorted_until(arr.begin(),arr.end())

For Example:

arr = {3,4,5,6,2,1}

is_sorted_until(arr.begin(),arr.end()) = > It return the iterator pointing to 2.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {345621};

    vector<int>::iterator it = is_sorted_until(arr.begin(), 
arr.end());

    cout << *it << "\n";

    return 0;
}


No comments:

Post a Comment