-
[C++] STL - map, set공부/C, C++ 2022. 5. 12. 17:33
- STL container - 시퀀스 컨테이너 / 연관 컨테이너
- 시퀀스 컨테이너: vector, list, deque 등 순서대로 데이터를 보관할때 사용
- 연관 컨테이너: map, set 등 <key, value> 형태로 데이터를 보관할때 사용. 찾고자하는 데이터를 빠르게 찾을 때 사용.
map, set
- key의 중복을 허용하지 않음
- 중복되는 key를 사용하는 경우에는 컨테이너 앞에 'multi'를 붙임. ex) multi_map, multi_set
- key 기준으로 데이터를 정렬하여 저장함
map
- Red-Black tree 자료구조를 가짐
- <key, value> 형태로 데이터를 저장
- key를 기준으로 오름차순 정렬함
- map 선언 예시)
#include <map> map <int, int> map1;
set
- map과 비슷하지만 map과 달리 key만 저장함
- key를 기준으로 오름차순 정렬함
- set 선언 예시)
#include <set> set <int> set1;
'공부 > C, C++' 카테고리의 다른 글
[C++] 부동소수점 숫자 자릿수 출력 (0) 2023.01.01 [C++] vector 객체의 최소값/최대값 찾기 (0) 2022.07.19 [C/C++] long long 데이터 형의 shift 연산 수행 (0) 2022.05.03 [C++] 공백으로 문자열 자르기, for each문 (나중에 포스트 하기) (0) 2022.03.18 [C++] string 공백 포함 입력, 입력 버퍼 비우기 (0) 2022.01.31