美文网首页
哈希链表

哈希链表

作者: 懒生活 | 来源:发表于2020-09-14 23:05 被阅读0次
    #define HTMAX 1133
    typedef struct node
    {
        int key;
        char nodename[11];
        struct node* last;
        struct node* next;
    }node_t;
    node_t nodes[1000];
    int nodeIdx = 0;
    node_t* htnode[HTMAX];
    
    
    node_t* cn()
    {
        node_t* nn = &nodes[nodeIdx];
        nn->key = 0;
        nn->last = 0;
        return nn;
    }
    
    void an(node_t* addnode)
    {
        int key = addnode->key;
        node_t* head = htnode[key];
        htnode[key] = addnode;
        addnode->next = head;
        if (head != 0)
            head->last = addnode;
    }
    
    void rn(node_t* delnode)
    {
        int key = delnode->key;
        node_t* bef = delnode->last;
        node_t* aft = delnode->next;
        if (bef == 0)
        {
            htnode[key] = aft;
        }
        
        if (bef != 0)
            bef->next = aft;
    
        if (aft != 0)
            aft->last = bef;
    }
    

    相关文章

      网友评论

          本文标题:哈希链表

          本文链接:https://www.haomeiwen.com/subject/kiatyktx.html