鏈表去重處理(去除鏈表中重復出現的節點)


#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\n",h->m);
   }
   return 0;
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM