Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int a[10000]= {0};
- struct node
- {
- int data;
- struct node *next;
- };
- int main()
- {
- struct node *prev,*head,*p;
- int n,i;
- scanf("%d",&n);
- head=NULL;
- for(i=0; i<n; i++)
- {
- p=(struct node*)malloc(sizeof(struct node));
- scanf("%d",&p->data);
- p->next=NULL;
- if(head==NULL)
- {
- head=p;
- }
- else
- {
- prev->next=p;
- }
- prev=p;
- }
- struct node* ptr,temp;
- ptr=head;
- while(ptr!=NULL)
- {
- a[ptr->data]++;
- if(a[ptr->data]>1)
- {
- ///delete this node
- prev->next=ptr->next;
- free(ptr);
- }
- ptr=ptr->next;
- }
- ptr=head;
- while(ptr!=NULL)
- {
- printf("%d ",ptr->data);
- ptr=ptr->next;
- }
- ///print the link list
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement