Advertisement
Radoan_Ahmed

Untitled

Nov 6th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  typedef struct Node
  4. {
  5.     int value;
  6.     struct Node *next;
  7. }Node;
  8.  
  9. Node *head = NULL;
  10. Node *temp = NULL;
  11. Node *list = NULL;
  12. int count(Node **head)
  13. {
  14.     int countt = 0;
  15.     temp = *head;
  16.     while(temp != NULL)
  17.     {
  18.         countt++;
  19.         temp = temp -> next;
  20.     }
  21.  
  22.     return countt;
  23. }
  24. void make_node(int n)
  25. {
  26.     while(n--)
  27.     {
  28.         Node *N = (Node*)malloc(sizeof(Node));
  29.         scanf("%d",&N -> value);
  30.         N -> next = NULL;
  31.         if(head == NULL)
  32.         {
  33.             head = N;
  34.             list = head;
  35.         }
  36.         else
  37.         {
  38.             list -> next = N;
  39.             list = list -> next;
  40.         }
  41.  
  42.     }
  43. }
  44.  
  45. int main()
  46. {
  47.     int x,y;
  48.     scanf("%d",&x);
  49.     make_node(x);
  50.     y=count(&head);
  51.     printf("The number of item is %d",y);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement