hashtable
- 链表数组:二级指针
- 基本操作 :初始化 插入 打印
#include <stdio.h>
#include <stdlib.h>
#include <string.h>typedef struct node {
int data;struct node *next;
}Node, *ptrNode;int N = 10;
typedef Node **table;int main()
{
table hashTable = (table)malloc(N*sizeof(ptrNode));memset(hashTable, 0, sizeof(ptrNode)*N);int i, key, value;while (1) {
scanf("%d", &value);if (value == -1) break;ptrNode p = (ptrNode)malloc(sizeof(Node));p->data = value;key = value % 10;p->next = hashTable[key];hashTable[key] = p;}for (i = 0; i < N; i++) {
ptrNode p = hashTable[i];printf("%d link: ", i);while (p) {
printf("%d ", p->data);p = p->next;}printf("\n");}return 0;
}