我是导入CSV数据,我正在尝试从中创建一个哈希表。我在设置条件语句以检查存储桶是否为空时遇到问题。我可以将信息放在桶中,但现在它会覆盖自己。任何人都可以帮我找出条件语句,以便我可以在我的哈希中插入出价吗?这是为了学校,否则我将使用标准库。
const unsigned int DEFAULT_SIZE = 179;
// forward declarations
double strToDouble(string str, char ch);
// define a structure to hold bid information
struct Bid {
string bidId; // unique identifier
string title;
string fund;
double amount;
Bid() {
amount = 0.0;
}
};
/**
* Default constructor
*/
HashTable::HashTable() {
// Initialize the structures used to hold bids
for (int i = 0; i < DEFAULT_SIZE; i++)
Table[i] = new Node;
}
unsigned int HashTable::hash(string key, const int DEFAULT_SIZE) {
//Implement logic to calculate a hash value
int index, sum = 0;
for (int i = 0; i < key.length(); i++)
sum += key[i];
index = sum % DEFAULT_SIZE;
return index;
}
void HashTable::Insert(Bid bid) {
// FIXME (5): Implement logic to insert a bid
int i;
Nodeptr newNode = new Node (bid);
int index = hash(bid.bidId, DEFAULT_SIZE);
/* if empty space */
Table[index] = newNode;
/*Else create new node and check if it null*/
}