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;
}
}

最新文章

  1. asp.net MVC excel数据导出
  2. Maven简单介绍
  3. Oracle_spatial的函数介绍[转]
  4. OD: DEP - Ret2Libc via VirtualProtect() &amp; VirtualAlloc()
  5. PHP面向对象多态性的应用
  6. 剖析C语言中a=a+++++a的无聊问题
  7. Unix命令行学习
  8. 做为一个Java程序员,你需要哪些傍身的技能?
  9. 升级到tomcat8时Artifact SpringMvcDemo:war exploded: Server is not connected. Deploy is not
  10. Borda count
  11. 3分钟带你了解PowerShell发展历程——PowerShell各版本资料整理
  12. ubuntu下动态链接库的编译和使用实例
  13. JeeSite
  14. asp.netcore 深入了解配置文件加载过程
  15. 浅谈最长上升子序列(LIS)
  16. [TJOI2012]桥(最短路+线段树)
  17. react 数据管理之state思想指南
  18. 20155325 Exp3 免杀原理与实践
  19. [2019BUAA软件工程]第0次个人作业
  20. memcached 学习笔记 5

热门文章

  1. SQL查询练习二(From LeetCode)
  2. 2.写给设计师看的HTML&amp;CSS入门指导
  3. Docker 部署Dotnet Core MVC项目
  4. 洛谷 P1143 进制转换
  5. jquery的滚动事件
  6. Loadrunner--基准测试的两种方法
  7. jmeter--响应断言
  8. Java基础学习总结(50)——Java事务处理总结
  9. mysql三种带事务批量插入
  10. 【u252】泽泽在巴西