Advertisement
Guest User

linkedlist

a guest
Jan 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct mylist
  4. {
  5. int data;
  6. struct mylist *next;
  7. struct mylist *prev;
  8. }node;
  9. int main()
  10. {
  11. node*a= (node*)malloc(sizeof(node));
  12. node*b= (node*)malloc(sizeof(node));
  13. node*c= (node*)malloc(sizeof(node));
  14.  
  15. a->data=7;
  16. b->data=2;
  17. c->data=6;
  18.  
  19. a->next=b;
  20. b->next=c;
  21. c->next=NULL;
  22.  
  23. c->prev=b;
  24. b->prev=a;
  25. a->prev=NULL;
  26. printf("The forward list: \n");
  27. while(a!=NULL)
  28. {
  29. printf("%d\n",a->data);
  30. a=a->next;
  31. }
  32. printf("NULL\n");
  33.  
  34. printf("The backward list: \n");
  35. while(c!=NULL)
  36. {
  37. printf("%d\n",c->data);
  38. c=c->prev;
  39. }
  40. printf("NULL\n");
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement