网站建设服务收费,网站建设基于,在线写代码的网站,高端网站案例网站建设1、unorder_map与map不同#xff1a;map的KEY值是有序的#xff0c;而unorder_map则是无序的#xff1b;2、unorder_map自定义的KEY值时需要注意思下面两点#xff1a; KEY为一个类时#xff0c;需要重载符号#xff1b; 需要自定义一个HASH类#xff0c;至于为什么map的KEY值是有序的而unorder_map则是无序的2、unorder_map自定义的KEY值时需要注意思下面两点· KEY为一个类时需要重载符号· 需要自定义一个HASH类至于为什么自己百度找原因下面贴上unorder_map的两类使用方法第一种#include #include using namespace std;class Node{public:Node();~Node();bool operator(const Node n) const;public:std::string m_strName;int m_iAge;};Node::Node() :m_iAge(0){}Node::~Node(){}bool Node::operator(const Node n) const{if (n.m_iAgem_iAge m_strNamen.m_strName){return true;}return false;}template struct hash{std::size_t operator()(const Node k) const{using std::size_t;using std::hash;using std::string;// Compute individual hash values for first,// second and third and combine them using XOR// and bit shifting:return ((hash()(k.m_strName))^(hash()(k.m_iAge) 1));}};int _tmain(int argc, _TCHAR* argv[]){std::unordered_map info;}第二种#include #include using namespace std;class Node{public:Node();~Node();bool operator(const Node n) const;public:std::string m_strName;int m_iAge;};Node::Node() :m_iAge(0){}Node::~Node(){}bool Node::operator(const Node n) const{if (n.m_iAgem_iAge m_strNamen.m_strName){return true;}return false;}struct KeyHasher{std::size_t operator()(const Node k) const{using std::size_t;using std::hash;using std::string;return ((hash()(k.m_strName)) ^ (hash()(k.m_iAge) 1));}};int _tmain(int argc, _TCHAR* argv[]){std::unordered_map info;}