双向循环链表结构以及定义

带头结点的双向循环链表如果链表为空,则头结点的前驱和后继都指向自身

尾节点的后继指向头结点,所以如果遍历则调节为p!=L,而不是p飞空

1)创建一个双向循环链表

void CreateList_DuL(DuLinkList &L)              
{
    int n;
    int i;
    DuLNode *p;
    L=(DuLinkList)malloc(sizeof(DuLNode));
 L->next=L->prior=L;
 cout<<"CreateList_L"<
    cout<<"Please input the Init DuLinkNode Number:  ";
    cin>>n;
    
    cout<<"Please input the data for DuLinkList Nodes: "<
    for(i=n;i>0;--i)
 {
    p=(DuLinkList)malloc(sizeof(DuLNode));
    cin>>p->data;                               //Reverse order inputing for Creating a LinkList
    p->prior=L;
    p->next=L->next;
    L->next->prior=p;
    L->next=p;
 }

  

 

posted on 2015-08-03 15:54  菜鸟基地  阅读(450)  评论(0)    收藏  举报

导航