Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- struct node
- {
- int data;
- struct node *next;
- }*start=NULL;
- void create()
- {
- char ch;
- do
- {
- struct node *new_node,*current;
- new_node=(struct node *)malloc(sizeof(struct node));
- printf("\n Enter the data : ");
- scanf("%d",&new_node->data);
- new_node->next=NULL;
- if(start==NULL)
- {
- start=new_node;
- current=new_node;
- }
- else
- {
- current->next=new_node;
- current=new_node;
- }
- printf("\n Do you want to creat another : ");
- ch=getche();
- }while(ch!='n');
- }
- void display()
- {
- struct node *new_node;
- printf("The Linked List : \n");
- new_node=start;
- while(new_node!=NULL)
- {
- printf("%d--->",new_node->data);
- new_node=new_node->next;
- }
- printf("NULL");
- }
- void RemoveDuplicates()
- {
- struct node *new_node;
- if(start==NULL)
- {
- printf("List is empty.");
- }
- else
- {
- new_node=start;
- for(new_node=start;new_node!=NULL;new_node=new_node->next)
- if(new_node==new_node->next)
- free(new_node);
- }
- }
- void main()
- {
- create();
- display();
- RemoveDuplicates();
- printf("\n");
- display();
- }
Add Comment
Please, Sign In to add comment