Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 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.             prev->next=ptr->next;
  37.             free(ptr);
  38.             ptr=prev;
  39.         }
  40.         prev=ptr;
  41.         ptr=ptr->next;
  42.     }
  43.     ptr=head;
  44.     while(ptr!=NULL)
  45.     {
  46.         printf("%d\n",ptr->data);
  47.         ptr=ptr->next;
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement