typedef struct node{ struct node *next,*pre; int data; } DSLink; void intiDSLink(DSLink *&L,int *a,int l){ //创建头结点 L=(DSLink*)malloc(sizeof(DSLink)); L->next=L->pre=NULL; DSLink *s,*pre; //创建结点 for(int i=0;i<l;i++){ //头插法 s=(DSLink*)malloc(sizeof(DSLink));//申请内存空间 s->data=a[i];//赋值 s->pre=L;//该结点的前指针指向前结点 s->next=L->next;//后指针指向前结点的后结点 L->next=s;//后结点 } DSLink *next=L->next,*t=L->next; //输出 while(next!=NULL){ cout<<next->data<<" "; next=next->next; } //删除重复 并且销毁 next=L->next; pre=L; while(next!=NULL){ if(pre->data==next->data){ //删除相等元素 pre->next=next->next; next->next->pre=pre; cout<<"删除"<<next->data<<" "; //释放结点 free(next); next=pre->next; }else{ pre=next; next=next->next; } } //输出 DSLink *n=t; while(n!=NULL){ cout<<n->data<<" "; n=n->next; } }