#include <stdio.h>
#include <stdlib.h>
struct ListNode;
struct HashTb1;
typedef unsigned int Index;
typedef struct ListNode *Position;
typedef struct HashTb1 *HashTable;
typedef Position List;
struct ListNode
{
int Element;
struct ListNode *Next;
};
struct HashTb1
{
int TableSize;
struct ListNode **TheLists;
};
#define MinTableSize 10
static int NextPrime( int N )
{
if( N % 2 == 0 )
N++;
return N;
}
Index Hash(int key, int TableSize)
{
return key % TableSize;
}
HashTable InitializeTable(int TableSize)
{
HashTable H;
int i;
if (TableSize < MinTableSize)
{
printf("Table size is too small.\n");
return NULL;
}
/* Allocate table */
H = (HashTable)malloc(sizeof(HashTable));
if (H == NULL)
{
printf("out of space!!!");
}
H->TableSize = NextPrime(TableSize);
/* Allocate arrary of lists */
H->TheLists = (struct ListNode **)malloc(sizeof(List) * H->T
散列表分离链接法初始化、插入、删去等操作(c)
最新推荐文章于 2020-10-19 21:37:27 发布