Advertisement
SOIKAT

Untitled

Mar 2nd, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. struct node
  5. {
  6. int data;
  7. struct node* link;
  8. };
  9. struct node* head=NULL;
  10. void insert(int data)
  11. {
  12. struct node* temp=(struct node*)malloc(sizeof(struct node));
  13.  
  14.  
  15. temp->data=data;
  16. temp->link=NULL;
  17. if(head==NULL)
  18. {
  19. head=temp;
  20. return;
  21. }
  22. struct node*p=head;
  23. while(p->link!=NULL)
  24. {
  25. p=p->link;
  26. }
  27. p=p->link=temp;
  28.  
  29. }
  30. void delet()
  31. {
  32. struct node *p,*q;
  33. p=q=head;
  34. int i;
  35. for(i=1;i<4-1;i++)
  36. {
  37. p=p->link;
  38. }
  39. q=p->link;
  40. p->link=q->link;
  41. q->link=NULL;
  42. free(q);
  43. }
  44. void Insert_At_Position()
  45. {
  46. struct node* temp=(struct node*)malloc(sizeof(struct node));
  47. int data;
  48. printf("Enter noda data which you insert 5 between 4:");
  49. scanf("%d",&data);
  50. temp->data=data;
  51. temp->link=NULL;
  52. struct node* p;
  53. p=head;
  54. int i;
  55. for(i=1;i<3-1;i++)
  56. {
  57. p=p->link;
  58. }
  59. temp->link=p->link;
  60. p->link=temp;
  61. }
  62. display()
  63. {
  64. struct node* p=head;
  65. while(p!=NULL)
  66. {
  67. printf("%d ",p->data);
  68. p=p->link;
  69. }
  70. printf("\n");
  71. }
  72. int main()
  73. {
  74. insert(2);
  75. insert(5);
  76. insert(4);
  77. insert(3);
  78. insert(1);
  79. display();
  80. printf("After 3 delete\n");
  81. delet();
  82. display();
  83. Insert_At_Position();
  84. display();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement