双向循环链表结构以及定义
带头结点的双向循环链表如果链表为空,则头结点的前驱和后继都指向自身
尾节点的后继指向头结点,所以如果遍历则调节为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;
}
浙公网安备 33010602011771号