线性表练习题2-6
#include<iostream> using namespace std; void Insert(DLinkList *&ha,DLinkList *&hb,int i) { DLinkList *p=ha->next,*q; int lena=1,j=0 while(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); }