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
- 라인트레이서
- 아두이노
- map
- Visual Micro
- Stack
- list
- LineTracer
- directx
- set
- C언어
- vector
- arduino compiler
- Deque
- 운영체제
- Arduino
- c++
- html
- priority_queue
- 컴퓨터 그래픽스
- queue
- WinAPI
- Algorithm
- 자료구조
- 아두이노 컴파일러
- stl
- 통계학
- Array
- 수광 소자
- 아두이노 소스
- 시스템프로그래밍
Archives
- Today
- Total
Kim's Programming
Algorithm - unique_copy() 본문
원형)
1 2 3 4 5 6 7 8 9 | //기본형 template <class InputIterator, class OutputIterator> OutputIterator unique_copy (InputIterator first, InputIterator last, OutputIterator result); //사용자 정의형 template <class InputIterator, class OutputIterator, class BinaryPredicate> OutputIterator unique_copy (InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); | cs |
의미)
[Iterator first, Iterator last) 사이에 있는 데이터들 중에서 중복되는 데이터들을 제외하여 Iterator result가 가리키는 위치에 복사를 합니다.
소스)
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 | #include<iostream> #include<algorithm> #include<vector> void Print(const std::vector<int>& target) { for (std::vector<int>::const_iterator iterPos = target.begin(); iterPos != target.cend(); iterPos++) std::cout << *iterPos << ' '; std::cout << std::endl; } void main() { std::vector<int> vector = { 10,20,20,20,30,30,20,20,10 }; std::vector<int> vectorCopy(9); std::vector<int>::iterator iter; std::cout << "Vector--->";Print(vector); std::cout << "VectorCopy--->";Print(vectorCopy); iter = std::unique_copy(vector.begin(), vector.end(), vectorCopy.begin()); vectorCopy.resize(std::distance(vectorCopy.begin(), iter)); std::cout << "Vector--->";Print(vector); std::cout << "VectorCopy--->";Print(vectorCopy); } | cs |
리턴값)
복사된 값들의 마지막을 가리키는 Iterator를 리턴합니다.
결과)
'STL - Algorithm > Algorithm - Modifying' 카테고리의 다른 글
Algorithm - reverse_copy() (0) | 2017.07.13 |
---|---|
Algorithm - reverse() (0) | 2017.07.13 |
Algorithm - unique() (0) | 2017.07.13 |
Algorithm - remove_copy_if() (0) | 2017.07.13 |
Algorithm - remove_copy() (0) | 2017.07.13 |