线性表练习题2-6

来源:互联网 发布:r11 邮箱软件 编辑:程序博客网 时间:2024/05/21 12:26
#include<iostream>using namespace std;void Insert(DLinkList *&ha,DLinkList *&hb,int i){DLinkList *p=ha->next,*q;int lena=1,j=0while(p->next!=ha){lena++;p=p->next;}if(i==0){p=hb->prior;p->next=ha->next;ha->next->prior=p;ha->next=hb->next;hb->next->prior=ha;}else if(i<lena){p=ha->next;while(j<i){p=p->next;j++;}q=p->next;p->next=hb->next;hb->next->prior=p;hb->prior=hb->prior;q->prior=hb->prior;}else{ha->prior->next=hb->next;hb->next->prior=ha->prior;hb->prior->next=ha;ha->prior=hb->prior;}free(hb);}