forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Bhupesh-V#506 from akash-arelli/master
Added is_sorted_until.md
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# is_sorted_until | ||
|
||
**Description :** std::is_sorted_until is used to find out the first unsorted element in the range [first, last). It returns an iterator to the first unsorted element in the range, so all the elements in between first and the iterator returned are sorted.</p> | ||
|
||
|
||
**Example** : | ||
|
||
```cpp | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
int main() | ||
{ | ||
int v[] = { 1, 2, 3, 4, 7, 10, 8, 9 }, i; | ||
|
||
int* ip; | ||
|
||
// Using std::is_sorted_until | ||
ip = std::is_sorted_until(v, v + 8); | ||
|
||
cout << "There are " << (ip - v) << " sorted elements in " | ||
<< "the list and the first unsorted element is " << *ip; | ||
return 0; | ||
} | ||
``` | ||
**[Run Code](https://rextester.com/NLRDYA45690)** |