重新构建结构哈希表

时间:2017-01-04 17:22:21

标签: c hash hashtable

我做了一个rehash功能,但它似乎没有工作,我不知道还能做什么。这是我的代码。我认为问题出在循环中

 struct hashT *hashtable; //global variable

struct hash{
 int size;
 int num_entries;
 struct Node table[];//the hash table
} *hashT;



 struct Node {
  struct Node *next;
 char* word;
 int count;
 int score;
 } *head;

 struct hastT Rehash(struct hashT *hashtable) {
     struct hastT *new_hashtable =  realloc(hashtable,2*sizeof(hashtable->table[hashtable->size]));
    struct Node *temp;
    unsigned long key;


new_hashtable->size = 2*hashtable->size;

for (int i=0; i< hashtable->size; i++){
    for (temp = hashtable->table[i]; temp; temp = temp->next;) {
        if (hashtable->table[i] != NULL) {
            key = hashF(hashtable->table[i]->word);
            new_hashtable->table[key]->word = hashtable->table[i]->word;
            new_hashtable->num_entries++;
        }
    }   
}
return (new_hashtable);

}        

0 个答案:

没有答案
相关问题