当前位置:网站首页>Hash table and full comments
Hash table and full comments
2022-07-07 02:36:00 【@Landscape post yuan】
#include "stdio.h"
#include "stdlib.h"
typedef struct{
int* elem; // Data element storage base address , Assign arrays dynamically
int count; // Number of current data elements
}HashTable;
int m=0; // Hash table length , Global variables
//HASHSIZE Define the hash table length as the length of the array
typedef enum { // Or not typedef, take Status On the front , The function called is preceded by enum
OK=1,SUCCESS=1,UNSUCCESS=0,HASHSIZE=12,NULLKEY=-32768
}Status;
Status InitHashTable(HashTable *H){ // Initialize hash table
int i;
m=HASHSIZE;
H->count=m;
H->elem=(int *)malloc(m*sizeof(int));
for(i=0;i<m;i++)
H->elem[i]=NULLKEY;
return OK;
}
int Hash(int key){ // Hash function key amount to qq account number
return key%m; // Division and remainder Return key
}
void InsertHash(HashTable* H,int key){ // Insert keywords into hash table
int addr=Hash(key); // Find the hash address
printf("The subscript of the inserted array position:%d\n",addr);
while(H->elem[addr]!=NULLKEY) // If it's not empty , Then conflict
addr=(addr+1)%m; // Develop linear detection of addressing
H->elem[addr]=key; // Until there is a space to insert keywords
}
Status SearchHash(HashTable H,int key,int* addr){ // Insert keywords into hash table
*addr=Hash(key); // Find the hash address
while(H.elem[*addr]!=key){ // If it's not empty , Then conflict
*addr=(*addr+1)%m; // Develop linear detection of addressing
if(H.elem[*addr]==NULLKEY||*addr==Hash(key)){
// If the loop goes back to the origin
// Key does not exist
return UNSUCCESS;
}
}
return SUCCESS;
}
int main(){
int i=0;
HashTable H;
InitHashTable(&H);
while(i<HASHSIZE){
InsertHash(&H,i); // Insert 12 Number
i++;
}
int key=0;
int addr; // Return the function of subscript
while(key<HASHSIZE){
if(SearchHash(H,key,&addr)==SUCCESS){ // Search the position of this number
printf("Print the position of this number:%d\n",addr);
} else{
printf("UNSUCCESS\n");
}
key++;
}
}
边栏推荐
- argo workflows源码解析
- The empirical asset pricing package (EAP) can be installed through pypi
- Infrared camera: juge infrared mag32 product introduction
- A new path for enterprise mid Platform Construction -- low code platform
- 1个月增长900w+播放!总结B站顶流恰饭的2个新趋势
- C # / vb. Net supprime le filigrane d'un document word
- Linear list --- circular linked list
- 【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
- 【Node学习笔记】chokidar模块实现文件监听
- 基于ensp防火墙双击热备二层网络规划与设计
猜你喜欢
This week's hot open source project!
Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?
如何从0到1构建32Core树莓派集群
#夏日挑战赛#数据库学霸笔记(下)~
AWS学习笔记(一)
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
MySQL --- 常用函数 - 字符串函数
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
随机推荐
How to build a 32core raspberry pie cluster from 0 to 1
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
电气工程及其自动化
Go swagger use
MySQL
你不可不知道的Selenium 8种元素定位方法,简单且实用
Introduction to the internal structure of the data directory of PostgreSQL
6-6 vulnerability exploitation SSH security defense
实施MES管理系统时,哪些管理点是需要注意的
Web3的先锋兵:虚拟人
Argo workflows source code analysis
#夏日挑战赛#数据库学霸笔记(下)~
CDB PDB 用户权限管理
Stm32f4 --- PWM output
1--新唐nuc980 NUC980移植 UBOOT,从外部mx25l启动
A new path for enterprise mid Platform Construction -- low code platform
fasterxml ToStringSerializerBase报错
The empirical asset pricing package (EAP) can be installed through pypi
测试优惠券要怎么写测试用例?
postgresql之integerset