问答题 阅读下列程序,指出其功能,并写出空格处应填上的语句。 void testl(element item,list_pointer ht[]) {int hash—value=hash(item.key); list_pointer ptr l trail=NULL。lead=ht[hash value]; for(;lead;trail=lead,lead=lead->1ink) (if{!strcmp(1ead->item.key,item.key)) (fprintf(stderr,“The key is in the table\n”);exit(1);) } ptr=(1ist_pointer)malloc(sizeof(1ist)); if(IS—FULL(ptr)) (fprintf(stderr,“The memoty is full\n”);exit(1);) ptr一>item=item;ptr一>1ink=NULL; if(trail) (1) ;else (2) ; }【浙江大学2002六(10分)】
【正确答案】正确答案:本题是在哈希表ht[]中插入值为item的元素,如该元素已在哈希表中,报告出错。 (1)trai一>link=ptr (2)ht[1rash—value]=ptr
【答案解析】