peanut0513   2년 전

아래 코드에서 예제 2번을 입력하면 정답대로 출력되는데

예제 3번을 입력하면 출력 순서가 25가 33보다 먼저 나옵니다..

해시맵은 정렬을 안 하니까 33이 먼저 나와야 하는 것 아닌가요 ?

아니면 해시맵 내부에서 25가 33보다 우선이라고 판단해서 25가 먼저 출력되는 건가요 ??

cr00   2년 전

unordered_map은 삽입 순서에 따라 정렬되지 않습니다

https://en.cppreference.com/w/...

Internally, the elements are not sorted in any particular order, but organized into buckets. Which bucket an element is placed into depends entirely on the hash of its key. Keys with the same hash code appear in the same bucket. This allows fast access to individual elements, since once the hash is computed, it refers to the exact bucket the element is placed into.

댓글을 작성하려면 로그인해야 합니다.