下列代码的功能是利用散列函数hash将一个元素插入到散列表ht[]中。其中list类型的结点包含element类型的项item、以及一个next指针。如果插入成功,则函数返回1,否则返回0。


下列代码的功能是利用散列函数hash将一个元素插入到散列表ht[]中。其中list类型的结点包含element类型的项item、以及一个next指针。如果插入成功,则函数返回1,否则返回0。

int insert( struct element item, list_pointer ht[] )
{
   int ret, hash_value;
   list_pointer ptr, trail, lead;

   ret = 1;
   hash_value = hash(item.key);
   trail = NULL; lead = ht[hash_value];
   for ( ; lead; trail = lead, lead = lead->next) {
      if (!strcmp(lead->item.key, item.key)) {
         printf("The key is in the table\n");
         ret = 0;
      }
   }
   if (ret) {
      ptr = (list_pointer)malloc(sizeof(struct list));
      (3分); ptr->next = NULL; if (trail) (3分); else (3分); } return ret; }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM