unordered_map 의 용법
C + + 11 은 auto, 예 를 들 어 for (type v: container) 등 새로운 기능 을 많이 도입 했다.
데이터 구조 면 에서 가장 눈 에 띄 는 것 은 unordered 를 도입 한 것 같 습 니 다.set 와 unorderedmap。일반적인 set 와 map 에 비해 그 내 부 는 더 이상 붉 은 나무 배열 의 키워드 가 아니 라 하 계 표를 사용 합 니 다.검색 효율 을 높 일 수 있 습 니 다.
그러나 구조 체 의 저장 과 매 핑 에 대해 다른 사람 이 말 하 는 것 을 별로 발견 하지 못 하고 방금 글 을 보고 배 웠 습 니 다 = =:http://choorucode.com/2012/06/26/c-using-unordered_set/
마크 를 해 보 세 요. 자신의 코드 를 붙 여 놓 으 면 다른 사람 이 사용 방법 을 찾 아 볼 수 있 습 니 다.
g + + 컴 파일 시 추가 주의: - std = c + 11
#include
#include
#include
#include
#include
using namespace std;
struct Node {
Node(int _x, int _y):x(_x), y(_y) {}
int x, y;
bool operator == (const Node &t) const {
return x==t.x ;
}
};
struct NodeHash {
std::size_t operator () (const Node &t) const {
return t.x * 100 + t.y;
}
};
unordered_set h_set;
unordered_map h_map;
int main(){
unordered_map::iterator arr;
h_set.insert(Node(1, 2));
int x, y;
cin >> x >> y;
if(h_set.find(Node(x, y)) == h_set.end())
cout << "Not found" << endl;
else cout << "Found succeed" << endl;
h_map[Node(1, 2)] = "World";
cout << h_map[Node(1, 2)] << endl;
return 0;
}
/*
: 1 2
:
1 2
Found succeed
World
*/
다음으로 전송:https://www.cnblogs.com/lengsong/p/11482627.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.