struct hashLink
{
KeyType key; /*the key is what you use to look up a hashLink*/
ValueType value; /*the value stored with the hashLink, an int in our case*/
struct hashLink *next; /*notice how these are like linked list nodes*/
};
struct hashMap
{
hashLink ** table; /*array of pointers to hashLinks*/
int tableSize; /*number of buckets in the table*/
int count; /*number of hashLinks in the table*/
};
hashLinks を使用して hashMap を反復処理しようとしています。これは正しいアプローチですか?hashLinks は配列内にあり、リンクされたリスト内でさらに多くの hashLinks がリンクされている場合があります。ポインターへのポインターの操作方法がわかりません。tableSize は、配列内の要素の量です。各配列位置には、最初にリンクされた hashLinks がさらに存在する場合があります。
for(int i = 0; i < ht->tableSize; i ++)
{
hashLink *current;
if (ht->table[i] != 0)
{
current = ht->table[i];
while(current->next !=0)
{
hashLink *next;
next = current->next;
free(current->key);
free(current);
current = next;
}
free(current->key);
free(current);
}
else
{
continue;
}
counter++;
}
}