美文网首页
循环双链表

循环双链表

作者: qianranow | 来源:发表于2021-03-26 09:52 被阅读0次

    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct Node {
        int data;
        struct Node *prior, *next;
    } DNode, *DLinkList;
    
    int InitList() {
        DNode *l = (DNode *)malloc(sizeof(DNode));
        if (l == NULL) return -1;
        l->prior = l;
        l->next = l;
        return 1;
    }
    
    int InsertNextNode(DNode *p, DNode *s) {
        if (p == NULL || s == NULL) return -1;
        s->next = p->next;
        p->next->prior = s;
        s->prior = p;
        p->next = s;
        return 1;
    }
    
    int DeleteNextNode(DNode *p) {
        if (p == NULL) return -1;
        DNode *q = p->next;
        p->next = q->next;
        q->next->prior = p;
        free(q);
        return 1;
    }
    
    int Empty(DLinkList l) {
        if (l->next == l) return 1;
        else return -1;
    }
    
    int isTail(DLinkList l, DNode *p) {
        if (p->next == l) return 1;
        else return -1;
    }
    

    相关文章

      网友评论

          本文标题:循环双链表

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