链表去重处理(去除链表中重复出现的节点)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct stu{
	int m;
	struct stu *l;
}st; 
int main()
{
   int m;
   st *h;
   while(scanf("%d",&m)!=EOF)	
   {
   	  st *l;
   	  h=new st;
   	  l=new st;
	  l=h;
   	  while(m--)
   	  {
   	  	st *s;
   	  	 s=new st;
   	  	 scanf("%d",&s->m);
   	  	 l->l=s;
   	  	 l=s;
		 }
		 l->l=NULL;
		 st *k;
		 k=new st;
		 l=h->l;
	    while(l!=NULL)
	    { 
	  	  int n;
	  	  n=l->m;
	  	  k=l;
	  	  while(k->l!=NULL)
	  	  {
	  	   	 if(n==k->l->m)
	  	   	 { 
	  	 		st *s;
	  	 		s=new st;
	  	 		s=k->l;
	  	 		k->l=s->l;
	  	 		free(s);
			    }
			 else
			 k=k->l;
		   }
		   l=l->l;
	    }
	    h=h->l;
	    while(h->l!=NULL)
	    {
	  	  printf("%d ",h->m);
	  	  h=h->l;
	     }
	    printf("%d
",h->m);
   }
   return 0;
}

  

原文地址:https://www.cnblogs.com/weidongya/p/7061370.html