수색…


소개

std :: unordered_map은 단지 연관 컨테이너입니다. 키와 맵에서 작동합니다. 이름대로 키가 맵에서 고유성을 유지하는 데 도움이됩니다. 매핑 된 값은 키와 관련된 내용 일뿐입니다. 이 키와 맵의 데이터 유형은 사전 정의 된 데이터 유형 또는 사용자 정의 중 하나 일 수 있습니다.

비고

이름이가는대로 정렬되지 않은 맵의 요소는 정렬 된 순서로 저장되지 않습니다. 그것들은 해시 값에 따라 저장되기 때문에 정렬되지 않은 맵의 사용은 O (1)을 사용하여 항목을 검색하는 것만 큼 많은 이점이 있습니다. 다른지도 컨테이너보다 빠릅니다. 이 예제에서는 연산자 ([])가 매핑 된 값에 직접 액세스하는 데 도움이되므로 구현하기가 매우 쉽다는 것을 알 수 있습니다.

선언 및 사용

이미 언급했듯이 모든 유형의 정렬되지 않은지도를 선언 할 수 있습니다. string과 integer 타입으로 first라는 이름의 정렬되지 않은 맵을 만들어 보겠습니다.

unordered_map<string, int> first; //declaration of the map 
first["One"] = 1; // [] operator used to insert the value 
first["Two"] = 2;
first["Three"] = 3;
first["Four"] = 4;
first["Five"] = 5;

pair <string,int> bar = make_pair("Nine", 9); //make a pair of same type
first.insert(bar); //can also use insert to feed the values

몇 가지 기본 기능

unordered_map<data_type, data_type> variable_name; //declaration

variable_name[key_value] = mapped_value; //inserting values

variable_name.find(key_value); //returns iterator to the key value

variable_name.begin(); // iterator to the first element

variable_name.end(); // iterator to the last + 1 element


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow