Advertisement
saira12tabassum19

Untitled

Nov 11th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct temp{
  5.  
  6. int x;
  7. struct temp *pt;
  8.  
  9. }*start=NULL;
  10.  
  11. void create()
  12. {
  13.  
  14. struct temp *ptr,*c;
  15. for(int i=1;i<=3;i++)
  16. {
  17. ptr=(struct temp*)malloc(sizeof(struct temp));
  18. ptr->x=i;
  19. ptr->pt=NULL;
  20. if(start==NULL)
  21. {
  22. start=ptr;
  23. c=ptr;
  24. }
  25. else{
  26.  
  27. c->pt=ptr;
  28. c=ptr;
  29. }
  30. }
  31.  
  32.  
  33. }
  34. void display()
  35. {
  36. struct temp *ptr=start;
  37. int k=0;
  38. while(k!=4)
  39. {
  40. printf("%d ",ptr->x);
  41. ptr=ptr->pt;k++;
  42. }
  43. }
  44. void l_insert()
  45. {
  46.  
  47. struct temp *ptr=start,*c;
  48. for(int i=2;i<=3;i++)
  49. {
  50. ptr=ptr->pt;
  51. }
  52. c=(struct temp*)malloc(sizeof(struct temp));
  53. c->x=5;
  54. c->pt=start;
  55. ptr->pt=c;
  56.  
  57.  
  58. }
  59. int main()
  60. {
  61.  
  62. create();
  63. //display();
  64. l_insert();
  65. display();
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement