Advertisement
Radoan_Ahmed

Untitled

Nov 6th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 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.  
  13. void search(Node **head,int n)
  14. {
  15.     int count = 0;
  16.     temp = *head;
  17.      while(temp != NULL)
  18.     {
  19.         if(temp -> value == n)
  20.         {
  21.             count ++;
  22.         }
  23.         temp = temp -> next;
  24.     }
  25.     if(count !=0)
  26.     {
  27.         printf("Yes\n");
  28.     }
  29.     else
  30.     {
  31.         printf("No\n");
  32.     }
  33. }
  34.  
  35. int count(Node **head)
  36. {
  37.     int countt = 0;
  38.     temp = *head;
  39.     while(temp != NULL)
  40.     {
  41.         countt++;
  42.         temp = temp -> next;
  43.     }
  44.  
  45.     return countt;
  46. }
  47. void make_node(int n)
  48. {
  49.     while(n--)
  50.     {
  51.         Node *N = (Node*)malloc(sizeof(Node));
  52.         scanf("%d",&N -> value);
  53.         N -> next = NULL;
  54.         if(head == NULL)
  55.         {
  56.             head = N;
  57.             list = head;
  58.         }
  59.         else
  60.         {
  61.             list -> next = N;
  62.             list = list -> next;
  63.         }
  64.  
  65.     }
  66. }
  67.  
  68. int main()
  69. {
  70.     int x,y,z;
  71.     scanf("%d",&x);
  72.     make_node(x);
  73.     y=count(&head);
  74.     printf("The number of item is %d\n",y);
  75.     printf("Enter a value for search: ");
  76.     scanf("%d",&z);
  77.     search(&head,z);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement