Advertisement
Zahid_hasan

Untitled

Mar 20th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct linkedlist
  4. {
  5. int num;
  6. int *ptr;
  7. int *pre_ptr;
  8. };
  9. typedef struct linkedlist node;
  10. int main()
  11. {
  12. node *first,*head,*temp=0,*previous=0;
  13. int count=0,option=1;
  14. first=0;
  15. while(option)
  16. {
  17. head=(node*)malloc(sizeof(node));
  18. printf("we get memory address: %d\n",head);
  19. printf("Enter the number: ");
  20. scanf("%d",&head->num);
  21. if(first!=0)
  22. {
  23. temp->ptr=head;
  24. head->pre_ptr=temp;
  25. temp=head;
  26. }
  27. else
  28. {
  29. temp=first=head;
  30. }
  31. fflush(stdin);
  32. printf("Press 1 to continue or press 0 to stop: ");
  33. scanf("%d",&option);
  34. }
  35. temp->ptr=0;
  36. temp=first;
  37. while(temp!=0)
  38. {
  39. printf("[%d] [%d][%d]",temp,previous,temp->num);
  40. temp=temp->ptr;
  41. previous=temp->pre_ptr;
  42. count++;
  43. }
  44. printf("[NULL]\n");
  45. printf("Total number of nodes: %d",count);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement