/**
* 散列表拉链法存储
*
* ①算法思想
*
* ②算法设计
*
*/
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <malloc.h>
#include <cstdlib>
#define MaxSize 20
#define INF 999999
//组成竖着的那个数组的一个个节点
typedef struct LinkNode{
int data;
struct LinkNode *next;
}LinkNode,*LinkList;
//竖着的那个数组
struct LinkHash{
LinkList Hash[MaxSize];
int p;//保存余数
};
//插入
bool Insert(LinkHash lh,int key){
int mod = key % lh.p;
LinkList Node = (LinkList)malloc(sizeof(LinkNode));
Node -> data = key;
Node -> next = lh.Hash[mod];
lh.Hash[mod] = Node;
return true;
}
//查找
bool Find(LinkHash lh,int key){
int mod = key % lh.p;
LinkList p = lh.Hash[mod];
while(p){
if(p -> data == key)
return true;
p = p -> next;
}
return false;
}
05-08
1174
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交