< 출처 >
- 강의명
C++ 코딩테스트 완전 정복 : 입문부터 실전 모의고사까지
- 목차
3-2 배열 [49:25]
< 내용 >
C++ STL(Standard Template Library)에 포함된 함수로,
컨테이너(예 : vector)에서 가장 큰 값을 가지는 요소의 위치(iterator)를 반환하는 함수.
- 예시
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
vector<int> nums = { 3, 5, 1, 8, 2 };
// 가장 큰 요소의 iterator를 반환
auto it = max_element(nums.begin(), nums.end());
// iterator가 가리키는 값을 출력
cout << "최댓값: " << *it << endl;
return 0;
}
/*
최댓값: 8
*/
'C++ > 알고리즘(Algorithm)' 카테고리의 다른 글
C++/자료형 유효 범위 확인, 콜라츠 추측 (0) | 2025.06.10 |
---|---|
C++/copy() & std::ostream_iterator<int>(cout, " ") (0) | 2025.06.10 |
C++/모듈러 연산-반복 패턴 처리 (0) | 2025.06.10 |
C++/STL-Map, Key값이 아닌 Value값으로 정렬 (0) | 2025.06.02 |
C++/난수 (0) | 2025.05.30 |