当前位置:网站首页>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++;
}
}
边栏推荐
- MySQL
- 6-6漏洞利用-SSH安全防御
- Detailed explanation of line segment tree (including tested code implementation)
- leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
- The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
- Apifox,你的API接口文档卷成这样了吗?
- Infrared camera: juge infrared mag32 product introduction
- 人脸识别应用解析
- AWS学习笔记(一)
- 1--新唐nuc980 NUC980移植 UBOOT,从外部mx25l启动
猜你喜欢
Web3's need for law
服装企业部署MES管理系统的五个原因
牛客编程题--必刷101之双指针篇
C语言练习题_1
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
fiddler的使用
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
postgresql之整體查詢大致過程
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
随机推荐
Go swagger use
实施MES管理系统时,哪些管理点是需要注意的
一文读懂Faster RCNN
MySQL
Stm32f4 --- PWM output
C#/VB.NET 删除Word文檔中的水印
Gee upgrade can realize one piece of run tasks
A new path for enterprise mid Platform Construction -- low code platform
C#/VB.NET 删除Word文档中的水印
fiddler的使用
一本揭秘字节万台节点ClickHouse背后技术实现的白皮书来了!
STM32 project -- Topic sharing (part)
Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
Lidar: introduction and usage of ouster OS
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
Alibaba cloud middleware open source past
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
测试优惠券要怎么写测试用例?
CDB PDB 用户权限管理