线性探测(开放寻址)中的删除是这样完成的,即为删除值的索引分配任何标记,例如“删除”。[可以在该索引处键入除 None 以外的任何值以指示该索引处的值已被删除]。请看下面的代码片段以指示我如何使用“删除”标记来填充删除值的索引
if self.table[index] == value:
print("key {} is found in the table and hence deletion tag is updated at that position".format(value))
self.table[index] = "Deletion"
现在,当再次搜索完成时会发生什么,这个位置不是 None 并且搜索将继续。请参阅下面的片段如何在线性探针中实现搜索
def search(self, value):
index = value % self.table_size
if self.table[index] != value:
while self.table[index] is not None and self.table[index] != value:
index = (index + 1) % self.table_size
if self.table[index] == value:
print("Key is found in the table")
else:
print("key is not found in the table")
还可以查看github 代码,解释线性探测中的删除而不中断查找。