Anyview数据结构第四章(按需自取)

404

#include "allinclude.h"  //DO NOT edit this line
void PrintKeys(HashTable ht, void(*print)(StrKeyType)){
/* 请调用形参中的print函数输出关键字 */
  int n , i;
  for (char c = 'A' ; c <= 'Z'; c++) {
    n = (c - 'A') % ht.size;
    i = n;
    while((n + 1) % ht.size  != i){
      if(-1 != ht.rcd[n].tag && ht.rcd[n].key[0] == c)
      print(ht.rcd[n].key);
      n  = (n + 1) % ht.size;
    }
  }
}

415

#include "allinclude.h"  //DO NOT edit this line
int BuildHashTab(ChainHashTab &H, int n, HKeyType es[])
{  // Add your code here
    int i , j , k;
    HLink p , q , t;
    j = 0;
    H.size = NUM;//哈希表容量
    H.count = 0;//哈希表记录个数
    H.rcd = (HLink *)malloc(H.size*sizeof(HLink));//开辟空间
    if(H.rcd == NULL) return UNSUCCESS;//开辟失败
    for (i = 0 ; i < H.size ; i++) 
    {
      H.rcd[i] = NULL;//置空
    }
    for (i = 0; i < n; i++)
    {
      p = (HLink)malloc(sizeof(HNode));
      p->data = es[i];
      k = Hash(H , p->data);//哈希函数计算地址
      t = H.rcd[k];
      while(t != NULL)
      {
        if(t->data == p->data){
          j = 1;//标记存在
          break;
        }
        t = t->next;
      }
      if(j == 0){
        q = H.rcd[k];
        p->next = q;
        H.rcd[k] = p;
        H.count++;
      }else{
        H.count++;
        j = 0;
      }
    }
    return SUCCESS;
}

430

#include "allinclude.h"
int countConflics(LHashTable H)
{
	Node** p=H.rcd;
	int sum=0;
	for(int i=0;i<H.size;i++)
	{
		int j=0;
		Node *q=H.rcd[i];
		while(q!=NULL)
		{
			j=1;
			sum++;
			q=q->next;
		}
		if(j==1)
		{
			sum--;
		}
	}
	return sum;  //Temporary code. Modify it if necessary.
}

435

#include "allinclude.h"
Node* searchLHash(LHashTable H, KeyType key, int &c)
{
	int p=H.hash(key,H.size);
	c=0;
	Node*np;
	for(np=H.rcd[p];np!=NULL;np=np->next)
	{
		if(np->r.key==key)
		{
			return np;
		}
		c++;
	}
	return NULL;  //Temporary code. Modify it if necessary.
}

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

提刀立码,调参炼丹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值