Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5. int data;
  6. struct node*next;
  7. };
  8. struct node* head=NULL;
  9. void insert(int x)
  10. {
  11. struct node*temp=(struct node*)malloc(sizeof(struct node*));
  12. temp->data=x;
  13. temp->next=NULL;
  14. if(head==NULL)
  15. {
  16. head=temp;
  17. }
  18. else
  19. {
  20. struct node*temp1=head;
  21. while(temp1->next!=NULL)
  22. {
  23. temp1=temp1->next;
  24. }
  25. temp1->next=temp;
  26.  
  27.  
  28. }
  29.  
  30. void print()
  31. {
  32. struct node*temp=head;
  33. while(temp!=NULL)
  34. {
  35. printf("%d ",temp->data);
  36. temp=temp->next;
  37.  
  38. }
  39. }
  40. int main()
  41. {
  42. insert(10);
  43. insert(20);
  44. insert(30);
  45. insert(40);
  46. insert(50);
  47. print();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement