/*思路:1,初始化2,建表3,输出单链表4,删除重复节点{两个指针遍历整个链表}5,输出*/#include#include typedef int ElemType;typedef struct LNode{ ElemType data; struct LNode * next;}LinkList;void InitList (LinkList *&L){ L=(LinkList *)malloc(sizeof (LinkList)); L->next=NULL;}void CreateList(LinkList *&L,ElemType a[],int n){ LinkList *s,*r;int i; L=(LinkList *)malloc(sizeof (LinkList)); r=L; for(i=0;i data=a[i]; r->next=s; r=s; } r->next=NULL;}void DispList(LinkList *L){ LinkList *p=L->next; while(p){ printf("%d ",p->data); p=p->next; } printf("\n");}void dele(LinkList *&L){ LinkList *p=L->next,*q,*r; while(p) { q=p; //------------------- while(q->next) { if(p->data==q->next->data) { r=q->next; q->next=r->next; free(r); } else q=q->next; } //-------------------- p=p->next; }}int main(){ LinkList *L; ElemType a[]={10,15,18,15,10}; InitList(L); CreateList(L,a,5); DispList(L); dele(L); DispList(L);}