其他分享
首页 > 其他分享> > 分离链接法的删除操作函数2021/5/5

分离链接法的删除操作函数2021/5/5

作者:互联网

 自己写的一直编译错误

bool Delete( HashTable H, ElementType Key ){
	Position tmp,ftmp;
	Index Pos;
	Pos=Hash( Key, H->TableSize );
	ftmp=H->Heads[Pos];
	tmp=H->Heads[Pos].Next;
	while(tmp&&strcmp(tmp ->Data,Key)){
		tmp=tmp->Next;
		ftmp=ftmp->Next;
	}
	if(!tmp) return false;
	else {
		ftmp->Next=tmp->Next;
		tmp->Next=NULL;
		free(tmp); 
		printf("%s is deleted from list Heads[%d]",Key,Pos);
		return true;
	}
}

 

这是别人的

bool Delete( HashTable H, ElementType Key ) {
    int s = Hash(Key,H -> TableSize);///题目给定的定位函数,确定Key可能在的位置
    List t = H -> Heads + s;///获得链表头结点
    while(t -> Next && strcmp(t -> Next -> Data,Key)) {
        t = t -> Next;
    }
    if(t -> Next == NULL) return false;
    PtrToLNode temp = t -> Next;
    t -> Next = t -> Next -> Next;
    free(temp);
    printf("%s is deleted from list Heads[%d]\n",Key,s);
    return true;
}

 

标签:tmp,Heads,删除,ftmp,Pos,Next,2021,Key,链接
来源: https://blog.csdn.net/weixin_47843380/article/details/116425901