unordered_map 의 용법

1664 단어
원본 블 로그:https://www.cnblogs.com/aaronzlq/p/3612629.html
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

좋은 웹페이지 즐겨찾기