赞
踩
目录
- s->next = p->next; //将结点s插入到结点p之后
- p->next->prior = s;
- s->prior = p;
- p->next = s;
头插法建立双链表
- //头插法建立双链表(有头结点)
- DLinkList List_HeadInsert(DLinkList &L) {
- L = (DLinkList)(malloc(sizeof(DNode)));
- DNode *s;
- L->next = NULL;
- L->prior = NULL;
- int data_insert;
- cin>>data_insert;
- while (data_insert != 9999) {
- s = (DNode*)(malloc(sizeof(DNode)));
- s->data = data_insert;
- if (L->next == NULL) { //第一个结点为空
- L->next = s;
- s->prior = L;
- s->next = NULL;
- }
- else {
- s->next = L->next;
- L->next->prior = s;
- s->prior = L;
- L->next = s;
- }
- cin>>data_insert;
- }
- return L;
- }
- p->next = q->next; //删除结点p的后继节点q
- q->next->prior = p;
- free(q);
- //删除操作的实现
- DLinkList DListDelete(DLinkList &L,int i){
- DNode *p = GetDNode(L,i-1); //得到被删结点的前驱节点
- DNode *q = p->next;
- p->next = q->next;
- q->next->prior = p;
- free(q);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。