Advertisement

C++实现一个堆(在对堆中的数据进行更改后能够自动进行调整)

阅读量:

库中带的堆结构,无法实现更改后再调整,此时需要自己实现

采用哈希表存储数据及其对应的索引位置,当需要对数据进行修改时,可通过索引位置对堆结构进行相应的调整。

复制代码
    #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 1
    
    #include<iostream>
    #include<vector>
    #include<hash_map>
    #include<string>
    
    using namespace std;
    
    //堆中存储数据使用自定义类型
    typedef struct Student
    {
    	int id;
    	int age;
    	string name;
    }Stu;
    
    
    template<class T>
    class heap_adjust
    {
    public:
    	void display()
    	{
    		for (auto i : data)
    			cout << i->id << " " << i->name << " " << i->age << endl;
    	}
    
    	void add(T

全部评论 (0)

还没有任何评论哟~