max-heap如何实现以下锦标赛?

时间:2016-04-12 01:06:27

标签: c++

我想阅读包含玩家及其预算的文本文件。播放器应存储在二进制最大堆中。堆由玩家的当前预算确定优先级,并且必须是基于数组的堆。我添加了部分代码,但我有以下混淆:

  1. 我在构造函数中的读数是否正确?
  2. 复制构造函数是对吗?
  3. 我不知道如何继续。有人可以指出我接下来应该做什么吗?
  4. 这是Heap.h

    #ifndef HEAP
    #define HEAP
    
    class Heap{
        public:
            Heap(string filename);// read the name and budget 
            Heap(const Heap &copy);
            void addPlayer(Player* newPlayer); // add player to the heap
            Player getPlayer();
            bool empty();
            unsigned int size(); // return number of nodes in heap
            void RemovePriorityPlayer(int heighest);
            // you still need heasp
            std::vector<Player> getArray();
    };
    
    #endif 
    

    这是Heap.cpp

    Heap::Heap(string filename) 
    {
       std::ifstream str;
       str.open(filename, ifstream::in);
       str.close();
    }
    
    Heap(const Heap &copy)
    {
       std::if stream copy.str;
    }
    
    void addPlayer(Player* newPlayer) // add player to the heap
    {
        string name;
        int budget;
        cin>>name>>budget;
        Player* pNewPlayer = new Player(name,budget);
    
        //if list is empty, make head of list this new player
    
        if(m-pHead == 0){
            m-pHead = pNewPlayer;
            m-pTail = m-pHead->GetNext();
        }
        else // otherwise find the end of the list and add the player there
        {
            m-pTail = pNewPlayer;
            m-pTail = m-pTail->GetNext();
        }
    }
    

    Player.h

    #ifndef PLAYERS
    #define PLAYERS
    
    class Player{
        public:
            int Card_hand;
            Player(string name, int budget);
            string getName();
            int getBudget();
            bool bet(int amount);
            void collectWinnings(int amount); 
    };
    
    #endif 
    

0 个答案:

没有答案