HashTable 解决碰撞(冲突)的方法 —— 分离链接法(separate chaining)
来源:互联网 发布:教乐器软件下载 编辑:程序博客网 时间:2024/05/16 09:08
1. ListNode 及 HashTable 的类型声明
声明
typedef int ElementType;typedef unsigned int Index;struct ListNode;typedef struct ListNode* Position;struct HashTbl;typedef struct HashTbl* HashTable;HashTable InitHashTable(int TableSize);void DestroyHashTable(HashTable H);Position Find(ElementType Element, HashTable H);void Insert(ElementType Element, HashTable H);;ElementType Retrieve(Position P);
定义
struct ListNode{ ElementType Element; Position Next; };typedef Position List;struct HashTbl { int TableSize; List* TheLists; };
2. HashTable 的构建
HashTable InitHashTable(int TableSize){ HashTable H; if (TableSize < MinTableSize){ Error(" ... "); return NULL; } H = (HashTable)malloc(sizeof(struct HashTbl)); if (!H) FatalError("out of space !!!"); H->TableSize = NextPrime(TableSize); H->TheLists = (List*)malloc(sizeof(struct ListNode)*H->TableSize); for (int i = 0; i < H->TableSize; ++i){ H->TheLists[i] = (List)malloc(sizeof(struct ListNode)); if (!H->TheLists[i]) FatalError(""); else H->TheLists[i]->Next = NULL; }}
3. 插入新的结点
void Insert(ElementType Key, HashTable H){ Position Pos, NewCell; List L; Pos = Find(key, H); if (!Pos){ NewCell = (Position)malloc(sizeof(struct ListNode)); if (!NewCell) FatalError(""); L = H->TheLists[Hash(Key, H->TableSize)]; NewCell->Next = L->Next; // 插入在首部 NewCell->Element = Key; L->Next = NewCell->Next; }}
0 0
- HashTable 解决碰撞(冲突)的方法 —— 分离链接法(separate chaining)
- 《数据结构与算法分析C++描述》 分离链接(separate chaining)哈希表的C++实现
- Hash 散列表(分离链接法解决冲突)
- HashTable(分离链接法)简单实现
- 哈希表(HashTable)的构造方法和冲突解决
- 数据结构(Java语言)——HashTable(分离链接法)简单实现
- jquery的链接(chaining)技术
- 数据结构——采用分离链接解决冲突问题的散列表
- HashTable(哈希表分离链接法)
- 数据结构--解决散列冲突,分离链接法
- 分离链接法解决hash冲突问题(C语言实现)
- 采用分离链接法的HashTable的实现
- 用分离链接法的HashTable的实现
- 哈希表分离链接发解决冲突
- 链接法解决hash解决碰撞之数组模拟方法
- 解决Hash碰撞冲突方法总结
- 解决Hash碰撞冲突方法总结
- 解决Hash碰撞冲突方法总结
- Vue.js结合vue-router和webpack编写单页路由项目
- WinForm C#写INI文件
- strtod()函数
- AWS EC2上搭建Cassandra集群到底如何呢?
- 因为孩子上学而搬家的故事
- HashTable 解决碰撞(冲突)的方法 —— 分离链接法(separate chaining)
- Sqlserver数据库通知应用程序
- 自动获取cell高度的第三方
- leetcode 64. Minimum Path Sum
- 数据库基础知识复习
- swift 对于NSDate日期获取年月日及其他操作
- 此谓生活-概述篇
- Android借鉴支付宝的思路解决 GridView网格线粗细的问题
- TCP/IP、Http、Socket的区别