構造体と連結リストを利用しての作成なのですが、ポインタ及び構造体のことが深く理解しておらず、エラーの原因を取り除くことが出来ません。
具体的には、以下のコードによって作成したbucketsという配列と連結リストの
型の違いについてを教えてください
pという変数をどのように代入して使うのかがわかりません。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HASH_M 3
//リスト
typedef struct list{
long key;
struct cell *next;
} List;
//ハッシュテーブル
typedef struct hash{
long bucket_num;
List **buckets;
} Hash;
//ハッシュ関数
long h(long x){
return x % HASH_M;
}
//ハッシュ作成
Hash *OpenHashTableMake(Hash *hash_table , long x){
long ind = h(x);
List *new = (List *)malloc(sizeof(List));
List *p;
if(new != NULL){
new->key = x;
new->next = NULL;
if(hash_table->buckets[ind] == NULL){
//先頭
hash_table->buckets[ind] = new;
}else{
p = (hash_table->buckets)[ind];
while(p->next == NULL){p=p->next;}
p->next = new;
}
}else{
printf("cant alloc new\n");
return NULL;
}
return hash_table;
}