我应该通过线性探测实现我自己的哈希表,但是我在删除功能方面遇到了麻烦。它没有正常工作,但我无法确定问题:
List<Contact> contacts = CrossContacts.Current.Contacts.ToList();
我的调试器将此显示为输出,所以显然我的方法存在表中的间隙问题:
public void remove(Student s){
if(s==null) throw new NullPointerException("Student is null"); /*check if student is null*/
if (!contains(s)){ /*stop if students is not in table*/
throw new NullPointerException();
}
int i = hashFunction(s);
for(int j = 0; j<array.length; j++){
if(s.equals(array[j])){ /*found student*/
array[j]=null; /*delete student*/
break;
}
}
for(int k= i; k<array.length; k++){ /* find out if next element exists, if yes, move it to the gap of deleted student */
if(!(array[k]==null)){
int tempnext= hashFunction(array[k]);
if(i <= tempnext){
array[i]=array[tempnext];
}
}
}
}
提前感谢您的帮助!