问题描述
我完全不知道如何用 C 编程语言为哈希表实现插入和获取函数。我有一个头文件、哈希函数文件和一个用于不同函数的文件。
哈希函数:
#include "hashfunc.h"
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
const int HASHVEKSIZE = 1048576;
uint32_t tilpro_hash(const char * s) {
uint32_t hash = 0;
//...
}
void put(Nod ** hashtable,char * key,char * value) {
// Todo
}
char * get(Nod ** hashtable,char * key) {
// Todo
}
void init(Nod ** vek) {
// Todo
}
头文件:
#ifndef tproHASHFUNC_H
#define tproHASHFUNC_H
#include <stdint.h>
#include "lista.h" // en headerfil för en modifierad dubbellänkad lista p3
uint32_t tilpro_hash(const char * s) ;
void put(Nod ** hashtable,char * value);
char * get(Nod ** hashtable,char * key);
void init(Nod ** vek);
#endif
#ifndef LISTA_H
#define LISTA_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct nod {
char key[512];
char value[512];
struct nod * next;
struct nod * prev;
};
typedef struct nod Nod;
void insertnod(Nod ** list,Nod * tobeadded);
void removenod(Nod ** list,Nod * toberemoved);
void printnod(Nod * node);
void printlist(Nod * node);
Nod * search(Nod * node,char * key);
#endif /* LISTA_H */
我发现很难知道如何开始编写 void put() 和 char * get()。很难知道所有的指针和东西。请帮忙!
main.c 看起来像:
#include "hashfunc.h"
// ...
extern const int HASHVEKSIZE;
// ...
int main() {
Nod ** myhashvek = malloc(sizeof(Nod *) * HASHVEKSIZE);
init(myhashvek);
put(myhashvek,"Adam","123321");
char * s = get(myhashvek,"Adam");
printf("Adam -> value = %s expecting Adam\n",s);
// ...
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)