class truct num span abs arr str log tab
- #define SIZE 1000 //定义Hash table的初始大小
- struct HashArray {
- int key;
- int count;
- struct Array * next;
- }
- Hash[SIZE]; //主函数中需要初始化
- void addHash(int num) //在Hash table中添加数据
- {
- int temp = abs(num % SIZE); //添加的数据可包括负数
- if (Hash[temp].key == 0) {
- Hash[temp].key = num;
- Hash[temp].count++;
- } else if (Hash[temp].key == num) {
- Hash[temp].count++;
- } else {
- struct HashArray * p = &Hash[temp];
- while (p - >key != num && p - >next != NULL) {
- p = p - >next;
- }
- if (p - >key == num) {
- p - >count++;
- } else {
- p - >next = (struct HashArray * ) malloc(sizeof(struct HashArray));
- p = p - >next;
- p - >key = num;
- p - >count = 1;
- p - >next = NULL;
- }
- }
- }
建立简单的Hash table(哈希表)by C language
class truct num span abs arr str log tab
原文:http://www.cnblogs.com/Blue-Keroro/p/7819472.html
来源: http://www.bubuko.com/infodetail-2391036.html