//--------------------------------------------------------------------------
//本例中采用链式解决冲突,便于查找
//hash表适合存储和查找操作
//构建hash要尽量减少冲突,hash表空间开的大一点,用空间换时间
//hash表的一种变种是位图表,stl中的bitmap<>,多用于大数据查找问题
//---------------------------------------------------------------------------
#ifndef _HASH_H
#define _HASH_H
#include<iostream>
using namespace std;
const int HASH_SIZE = 11;
typedef struct linknode{
int data;
struct linknode *next ;
}hashnode,*phashnode;
class HASH{
public:
phashnode initHash(); //hash表的初始化
void createHash(int arr[], int size, phashnode _hash); //hash表的构建
int hash_func(int value); //hash函数
int searchHash(phashnode _hash, int value); //hash表的查找
};
phashnode HASH::initHash() {
int i;
phashnode myhash= new hashnode[HASH_SIZE];
if(!myhash) {
return NULL;
}
for(i=0;i<HASH_SIZE;++i) {
C++类实现hash表的抽象数据结构(链式解决冲突)
最新推荐文章于 2023-02-25 11:44:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)