*컨테이너에서 쓰이는 기본적인 데이터 조작 방식.
1.삽입
2.삭제
3.검색
4.순회
*Set
( Key = Value ) => 키와 값이 똑같은 데이터로 담는 컨테이너
=> 결국, Key = Value 것만 빼면 map 과 동일
*multimap
=> 동일한 Key 에 대한 '중복된 데이터' 를 넣어줄 수 있음.
=> m[5] = 500 => 문법 막혀있음. => 유일하지않은 데이터.
=> erase(1); => Key = 1 인 데이터 모두 삭제.
multimap<int, int>::iterator FindIt = mm.find(1);
auto itPair = mm.equal_range(1);
auto FindBegin = mm.lower_bound(1);
auto FindEnd = mm.upper_bound(1);
for (auto It = FindBegin; It != FindEnd; ++It)
{
cout << It->first << " " << It->second << endl;
}
=> lower_bound / upper_bound 로 해당 키의 중복된 값들의 범위를 구할 수 있음.
*multiset
=> multimap 과 동일한 방식으로 Key 에 대한 '중복된 데이터' 를 넣어줄 수 있음.
다만, Set 일 뿐.
multiset<int> mset;
mset.insert(10);
mset.insert(10);
mset.insert(10);
mset.insert(10);
mset.insert(20);
mset.insert(30);
auto mitPair = mset.equal_range(1);
auto mFindBegin = mset.lower_bound(10);
auto mFindEnd = mset.upper_bound(10);
for (auto It = mFindBegin; It != mFindEnd; ++It)
{
cout << *It << endl;
}
본 내용은 인프런의 루키스님 강의를 듣고 정리한 내용입니다.
'프로그래밍 > C++' 카테고리의 다른 글
#61. 중괄호 초기화 { } (0) | 2022.07.22 |
---|---|
#60. Algorithm (0) | 2022.07.21 |
#58. Map (0) | 2022.07.21 |
#57. deque (0) | 2022.07.21 |
#56. list (0) | 2022.07.21 |