哈希表的C语言链表实现
1 哈希表的特点
结合了数组(索引快)和链表(可灵活增删结点)的优点。
2 代码实现
2.1 链表部分
2.1.1 链表结点的结构
typedef struct __tag_node{
int id;
struct __tag_node *pNext;
int satellite;
}Node;
2.1.2 创建链表
Node *LinkedList_Create(void)
{
Node *p = malloc(sizeof(Node));
if(p == NULL){
return NULL;
}
p->pNext = NULL;
p->id = 0; // The total quantity of nodes
return p;
}
2.1.3 销毁链表
void LinkedList_Destroy(Node *list)
{
Node *p = list->pNext; // Reserved header node
while(p){
Node *tmp = p;
p = p->pNext;
free(tmp);
}
list->pNext = NULL;
list->id = 0;
}
2.1.4 头插新结点
/**
* @brief Inserting a new node in the linked list
* @param list, The linked list will be inserted
* @param id, id number
* @param the satellite value of the id
**/
int LinkedList_InsertHead(Node