Advertisement
S_h_u_v_r_o

Fall17

Mar 3rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. //Fall-17
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5.  
  6. typedef struct x
  7. {
  8. int data;
  9. struct x *next;
  10. }x;
  11. x *head=NULL,*temp;
  12.  
  13. void insertBetween(int a,int b)
  14. {
  15. x *c;
  16. c=(x*)malloc(sizeof(x));
  17. c->data=b;
  18. temp=head;
  19. while(temp->data!=a)
  20. {
  21. temp=temp->next;
  22. }
  23. c->next=temp->next;
  24. temp->next=c;
  25.  
  26. temp=head;
  27. while(temp!=NULL)
  28. {
  29. printf("%d ",temp->data);
  30. temp=temp->next;
  31. }
  32.  
  33. }
  34.  
  35. void count()
  36. {
  37. int a=0;
  38. temp=head;
  39. while(temp!=NULL)
  40. {
  41. a++;
  42. temp=temp->next;
  43. }
  44. printf("\n%d",a);
  45.  
  46. }
  47.  
  48. int main()
  49. {
  50. x *a,*b,*c,*d;
  51. a=(x*)malloc(sizeof(x));
  52. b=(x*)malloc(sizeof(x));
  53. c=(x*)malloc(sizeof(x));
  54. d=(x*)malloc(sizeof(x));
  55.  
  56. a->data=3;
  57. a->next=b;
  58. head=a;
  59. b->data=10;
  60. b->next=c;
  61. c->data=2;
  62. c->next=d;
  63. d->data=1;
  64. d->next=NULL;
  65.  
  66.  
  67. while(a!=NULL)
  68. {
  69. printf("%d ",a->data);
  70. a=a->next;
  71. }
  72.  
  73. printf("\n");
  74.  
  75. insertBetween(10,15);
  76.  
  77. count();
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement