15 5 C:\Users\86131\Documents\哈希找人名.cpp [Error] anonymous type with no linkage used to declare function int InsertHT(<anonymous struct>*, int\\&, KeyType, int) with linkage [-fpermissive]
时间: 2023-07-21 13:44:57 浏览: 60
这个错误是由于在声明函数 `InsertHT` 时使用了没有链接的匿名结构体,导致编译器无法识别该结构体。建议将结构体命名并重新声明函数,例如:
```c++
struct HashTable {
// 结构体成员
};
int InsertHT(HashTable* H, int& P, KeyType K, int D) {
// 函数实现
}
```
这样就能避免这个错误了。
相关问题
std::thread::current().id()怎么转换为整数
您可以使用 std::hash<std::thread::id> 来将 std::thread::id 转换为整数类型的哈希值。例如:
std::thread::id id = std::this_thread::get_id();
std::size_t id_hash = std::hash<std::thread::id>{}(id);
int id_int = static_cast<int>(id_hash);
给出实例:在哈希表中插入Node(k, v)。使用哈希函数self.hash()。
好的,这是一个关于哈希表的问题。在哈希表中插入Node(k, v)的过程中,我们需要使用哈希函数self.hash()来计算键k的哈希值,然后将Node(k, v)插入到哈希表中对应的位置。具体的实现过程可以参考以下代码:
```
class Node:
def __init__(self, key, value):
self.key = key
self.value = value
class HashTable:
def __init__(self):
self.size = 10
self.table = [[] for _ in range(self.size)]
def hash(self, key):
return key % self.size
def insert(self, key, value):
hash_value = self.hash(key)
for node in self.table[hash_value]:
if node.key == key:
node.value = value
return
self.table[hash_value].append(Node(key, value))
```
在这个例子中,我们定义了一个Node类来表示哈希表中的节点,其中包含键和值两个属性。我们还定义了一个HashTable类来表示哈希表,其中包含一个大小为10的列表table,用于存储节点。在插入节点时,我们首先使用哈希函数self.hash()计算键的哈希值,然后在对应的位置上查找是否已经存在该键的节点,如果存在,则更新节点的值,否则将新节点插入到列表中。