what does it do?
SYNTAX:-
version 1
template <class IteratorLoc>
ForwardIterator is_sorted_until(IteratorLoc first, IteratorLoc last);
version 2
template <class IteratorLoc, class Compare_function>
ForwardIterator is_sorted_until(IteratorLoc first, IteratorLoc last, Compare_function function_name);PARAMETERS-
first - iterator to the first position of the range.last - iterator of the last position of the range.function_name - is the function pointer of the bool fucntion which returns true or false after comparision.Complexity-
Linear i.e, O(n)Link to repository-
https://github.com/pyskmr/D4datastructures/tree/master/CPP%20algorithm%20header%20file/is_sorted_until
IN THIS ARTICLE WE ARE SEEING HOW TO USE THIS ALGORITH HEADER FUCNTION ON list CONTAINER.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 // is_sorted_until example
#include <iostream>
#include <algorithm> // is_sorted_until
#include <list> // list
using namespace std;
/*
procedure to call is_sorted_until
*/
void check(list<int> l)
{
list<int>::iterator it;
for(it =l.begin();it!=l.end();it++)
{
cout<<*it<<" ";
}
list<int>::iterator i=is_sorted_until(l.begin(),l.end()); //you can also give your range here
i!=l.end()?cout<<"\nafter "<<*i<<" the range is unsorted\n\n":cout<<"\nsorted\n\n";
}
int main () {
list<int> l1 {2,4,8,9,1,99};
list<int> l2 {1,3,9,12,28,99};
check(l1);
check(l2);
return 0;
}OUTPUT:-NOTE :- cant be implemented with any container which do not support iterator like, stack and queue.
Comments