使用自定义类型作为键的C+无序映射
unordered_map
#include <iostream>#include <algorithm>#include <unordered_map>using namespace std;class node;class Solution;class Node {public: int a; int b; int c; Node(){} Node(vector<int> v) { sort(v.begin(), v.end()); a = v[0]; b = v[1]; c = v[2]; } bool operator==(Node i) { if ( i.a==this->a && i.b==this->b &&i.c==this->c ) { return true; } else { return false; } }};int main() { unordered_map<Node, int> m; vector<int> v; v.push_back(3); v.push_back(8); v.push_back(9); Node n(v); m[n] = 0; return 0;}
我想,我需要告诉C+如何散列类 Node
然而,我不太清楚该如何做。我如何完成这些任务?
UYOU
相关分类