我正在尝试实施字典.如果您在我的代码中发现缺陷而不是改变整个逻辑,我将不胜感激.
样本输入
3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry
样品输出:
sam = 99912222
未找到
harry = 12299933
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
struct Dict {
char key[100];
int value;
};
struct Dict *array;
int inputsize;
int getHashKey(char *key){
return strlen(key)%inputsize;
}
void insert(char *key, int value){
int i =0;
int hashkey = getHashKey(key);
/* Already inserted. Return */
if(!strcmp (array[hashkey].key,key)){
return;
}
/* Check if empty space. else, Get the next available space. */ …Run Code Online (Sandbox Code Playgroud)