Guest User

Untitled

a guest
Jan 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include<stdio.h>
  2. struct node
  3. {
  4. int data;
  5. struct node *next;
  6. }*start=NULL;
  7.  
  8. void create()
  9. {
  10. char ch;
  11. do
  12. {
  13. struct node *new_node,*current;
  14.  
  15. new_node=(struct node *)malloc(sizeof(struct node));
  16.  
  17. printf("\n Enter the data : ");
  18. scanf("%d",&new_node->data);
  19. new_node->next=NULL;
  20.  
  21. if(start==NULL)
  22. {
  23. start=new_node;
  24. current=new_node;
  25. }
  26. else
  27. {
  28. current->next=new_node;
  29. current=new_node;
  30. }
  31.  
  32. printf("\n Do you want to creat another : ");
  33. ch=getche();
  34. }while(ch!='n');
  35. }
  36.  
  37.  
  38. void display()
  39. {
  40. struct node *new_node;
  41. printf("The Linked List : \n");
  42. new_node=start;
  43. while(new_node!=NULL)
  44. {
  45. printf("%d--->",new_node->data);
  46. new_node=new_node->next;
  47. }
  48. printf("NULL");
  49. }
  50. void RemoveDuplicates()
  51. {
  52. struct node *new_node;
  53.  
  54. if(start==NULL)
  55. {
  56. printf("List is empty.");
  57. }
  58. else
  59. {
  60. new_node=start;
  61. for(new_node=start;new_node!=NULL;new_node=new_node->next)
  62. if(new_node==new_node->next)
  63. free(new_node);
  64. }
  65. }
  66. void main()
  67. {
  68. create();
  69.  
  70. display();
  71.  
  72. RemoveDuplicates();
  73. printf("\n");
  74. display();
  75.  
  76. }
Add Comment
Please, Sign In to add comment