栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++ STL自定义类和比较规则

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++ STL自定义类和比较规则

C++ STL自定义类和比较规则
// HashTable ->无法测试,改测set吧
#include
#include
#include
#include
class DellCom{
    public:
        int type;
        int price;
    public:
        DellCom(int name,int price):type(name),price(price){

        }
        ~DellCom(){

        }
        // string show(){
        //     return ("Type: "+this->type+" Price: "+this->price);
        // }
        int getPrice() const{
            return this->price;
        }
};
struct Hash_Dec{
    size_t 
    operator()(const DellCom& de)const noexcept{
        // cout<
    bool 
    operator()(const DellCom& x,const DellCom& y) const noexcept{
        int x1= x.getPrice();
        int x2= y.getPrice();
        return x1==x2;
    }
};
void test_hashTable(){
    unordered_set sets;
    // unordered_set sets;
    // unordered_set sets;
    // sets.insert(3);
    sets.insert(DellCom(12,1));
    sets.insert(DellCom(3,2));
    sets.insert(DellCom(3,25));
    sets.insert(DellCom(3,24));
    cout << " sets size " << sets.size() << endl;
    cout << " sets max_size " << sets.max_size() << endl;
    // cout << " bucket size" << sets.bucket_size()< li;
    for (unsigned i = 0; i < 7; i++)
    {
        cout<<" bucket"< 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/917091.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号