Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Node
- {
- int value;
- struct Node *next;
- }Node;
- Node *head = NULL;
- Node *temp = NULL;
- Node *list = NULL;
- void search(Node **head,int n)
- {
- int count = 0;
- temp = *head;
- while(temp != NULL)
- {
- if(temp -> value == n)
- {
- count ++;
- }
- temp = temp -> next;
- }
- if(count !=0)
- {
- printf("Yes\n");
- }
- else
- {
- printf("No\n");
- }
- }
- int count(Node **head)
- {
- int countt = 0;
- temp = *head;
- while(temp != NULL)
- {
- countt++;
- temp = temp -> next;
- }
- return countt;
- }
- void make_node(int n)
- {
- while(n--)
- {
- Node *N = (Node*)malloc(sizeof(Node));
- scanf("%d",&N -> value);
- N -> next = NULL;
- if(head == NULL)
- {
- head = N;
- list = head;
- }
- else
- {
- list -> next = N;
- list = list -> next;
- }
- }
- }
- int main()
- {
- int x,y,z;
- scanf("%d",&x);
- make_node(x);
- y=count(&head);
- printf("The number of item is %d\n",y);
- printf("Enter a value for search: ");
- scanf("%d",&z);
- search(&head,z);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement