双向循环链表创建

89 阅读1分钟

定义

typedef struct linkLNode {
    int data;
    struct linkLNode *next;
    struct linkLNode *prior;
} ListNode,*LinkList; 

创建

void createLinkList(LinkList &head)
{
    head = new ListNode;
    head->prior = NULL;
    head->next = NULL;
    cin >> head->data;
    LinkList list = head;
    while (1)
    {
        LinkList body = new LNode;
        body->prior = NULL;
        body->next = NULL;
        cin >> body->data;
        if (!body->data)
        {
            delete body;
            break;
        }
        list->next = body;
        body->prior = list;
        list = list->next;
    }
    list->next = head;
    head->prior = list;
}