Guest User

Untitled

a guest
Feb 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. struct node{
  4. int data;
  5. struct node*next;
  6. };
  7. void printlist(struct node *n)
  8. {
  9. while(n !=NULL)
  10. {
  11.  
  12. printf("%d",n->data);
  13. n=n->next;
  14.  
  15. }
  16.  
  17. }
  18. int main()
  19. { //declare the list
  20. struct node*head=NULL;
  21. struct node*first=NULL;
  22. struct node*second=NULL;
  23.  
  24. head=(struct node*)malloc(sizeof(struct node));
  25. first=(struct node*)malloc(sizeof(struct node));
  26. second=(struct node*)malloc(sizeof(struct node));
  27. head->data=1;
  28. head->next=first;
  29. first->data=5;
  30. first->next=second;
  31. second->data=7;
  32. second->next=NULL;
  33. printlist(head);
  34. return 0;
  35.  
  36. }
Add Comment
Please, Sign In to add comment