Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 라인트레이서
- priority_queue
- LineTracer
- map
- C언어
- Arduino
- Deque
- 시스템프로그래밍
- 아두이노
- vector
- Visual Micro
- WinAPI
- Algorithm
- 아두이노 컴파일러
- 자료구조
- 수광 소자
- 통계학
- c++
- arduino compiler
- 컴퓨터 그래픽스
- Stack
- directx
- list
- html
- stl
- Array
- 운영체제
- 아두이노 소스
- queue
- set
Archives
- Today
- Total
Kim's Programming
Algorithm - is_sorted() 본문
원본)
1 2 3 4 5 6 7 | //기본형 template <class ForwardIterator> bool is_sorted (ForwardIterator first, ForwardIterator last); //사용자 정의형 template <class ForwardIterator, class Compare> bool is_sorted (ForwardIterator first, ForwardIterator last, Compare comp); | cs |
의미)
[Iterator first, Iterator last)사이에 있는 데이터들이 오름차순으로 정렬이 되어있으면 true를 리턴합니다.
소스)
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 | #include <iostream> #include <algorithm> #include <vector> void Print(const std::vector<int>& target) { for (std::vector<int>::const_iterator iterPos = target.cbegin(); iterPos != target.cend(); iterPos++) std::cout << *iterPos << " "; std::cout << std::endl; } void main() { std::vector<int> vector = { 25, 5,15,10,30,20,15 }; Print(vector); if (std::is_sorted(vector.begin(), vector.end())) std::cout << "sorted!" << std::endl; else std::cout << "not sorted!" << std::endl; std::sort(vector.begin(), vector.end()); Print(vector); if (std::is_sorted(vector.begin(), vector.end())) std::cout << "sorted!" << std::endl; else std::cout << "not sorted!" << std::endl; } | cs |
내용)
[Iterator first, Iterator last)사이에 있는 데이터들이 오름차순으로 정렬이 되어있다면 true를 리턴하고 그 외의 경우 false를 리턴합니다.
결과)
'STL - Algorithm > Algorithm - Sorting' 카테고리의 다른 글
Algorithm - is_sorted_until() (0) | 2017.06.30 |
---|---|
Algorithm - partial_sort_copy() (0) | 2017.06.30 |
Algorithm - partial_sort() (0) | 2017.06.30 |
Algorithm - stable_sort() (0) | 2017.06.30 |
Algorithm - sort() (0) | 2017.06.30 |