입력 및 출력 반복기 사용에 관한 실제 질문이 있습니다. 함수의 제목은 다음과 같습니다.입력 및 출력 반복기
template<class InpIter,class OutpIter>
OutpIter my_unique_copy(InpIter first, InpIter last, OutpIter result)
이 함수는 [first, last] 범위의 요소를 결과로 복사해야합니다. 연속되는 중복 요소 그룹에서 첫 번째 값만 복사됩니다. 반환 값은 요소가 복사되는 범위의 끝입니다. 복잡성 : 선형
나는 아직 나는 이것이 당신이,가는 있었는지 생각
template<class InpIter,class OutpIter>
OutpIter my_unique_copy(InpIter first, InpIter last, OutpIter result){
InpIter current=first;
first++;//point to second element
while(first!=last){
while(*first==*current){//Keep comparing elements to current to see if they're same
first++;
}
result=current;
current=first;
result++;
first++;
}
return result;
}
그래, 뭐가 문제 야? :) – jrok
컴파일러는 물지 않습니다. 편안하게 접근하는 유일한 방법은 시도해 보는 것입니다. – Cogwheel
또한 'unique_copy()'를 사용할 수도 있습니다 – Kunal