Advertisement
Saleh127

Untitled

Feb 28th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int a[10000]= {0};
  4. struct node
  5. {
  6. int data;
  7. struct node *next;
  8. };
  9. int main()
  10. {
  11. struct node *prev,*head,*p;
  12. int n,i;
  13. scanf("%d",&n);
  14. head=NULL;
  15. for(i=0; i<n; i++)
  16. {
  17. p=(struct node*)malloc(sizeof(struct node));
  18. scanf("%d",&p->data);
  19. p->next=NULL;
  20. if(head==NULL)
  21. {
  22. head=p;
  23. }
  24. else
  25. {
  26. prev->next=p;
  27. }
  28. prev=p;
  29. }
  30. struct node* ptr,temp;
  31. ptr=head;
  32. while(ptr!=NULL)
  33. {
  34. a[ptr->data]++;
  35. if(a[ptr->data]>1)
  36. {
  37. ///delete this node
  38. prev->next=ptr->next;
  39. free(ptr);
  40. }
  41. ptr=ptr->next;
  42. }
  43. ptr=head;
  44. while(ptr!=NULL)
  45. {
  46. printf("%d ",ptr->data);
  47. ptr=ptr->next;
  48. }
  49. ///print the link list
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement