【发布时间】:2017-11-20 06:23:21
【问题描述】:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 10
// A hashtable is a mixture of a linked list and array
typedef struct node NODE;
struct node{
int value;
NODE* next;
};
int hash(int);
void insert(int,NODE **);
int main(){
NODE* hashtable[SIZE];
insert(12,&hashtable[SIZE]);
printf("%d\n",hashtable[5]->value);
}
int hash(int data){
return data%7;
}
void insert(int value,NODE **table){
int loc = hash(value);
NODE* temp = malloc(sizeof(NODE));
temp->next = NULL;
temp->value = value;
*table[loc] = *temp;
printf("%d\n",table[loc]->value);
}
上面的代码打印: 12 和 27475674(可能是随机数。)
如何让它打印 12 和 12,即如何在数组中进行更改。我想用为存储值而创建的节点的位置填充数组 [5]。
【问题讨论】:
标签: c arrays pointers hashtable