我想阅读包含玩家及其预算的文本文件。播放器应存储在二进制最大堆中。堆由玩家的当前预算确定优先级,并且必须是基于数组的堆。我添加了部分代码,但我有以下混淆:
这是Heap.h
#ifndef HEAP
#define HEAP
class Heap{
public:
Heap(string filename);// read the name and budget
Heap(const Heap ©);
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 ©)
{
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