-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLL13(Searching node)
47 lines (47 loc) · 955 Bytes
/
LL13(Searching node)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include<stdlib.h>
#include<stdbool.h>
struct node
{
int data;
struct node* next;
}*head=NULL;
void createlist(int n)
{
struct node *new_node,*temp;
int i,num;
head=(struct node*)malloc(sizeof(struct node));
scanf("%d",&num);
head->data=num;
head->next=NULL;
temp=head;
for(i=2;i<=n;i++)
{
new_node=(struct node*)malloc(sizeof(struct node));
scanf("%d",&num);
new_node->data=num;
new_node->next=NULL;
temp->next=new_node;
temp=temp->next;
}
}
bool checknode(struct node* head, int x)
{
struct node* current = head;
while (current != NULL)
{
if (current->data == x)
return true;
current = current->next;
}
return false;
}
int main()
{struct node* new_node =(struct node*) malloc(sizeof(struct node));
int n,x;
scanf("%d",&n);
createlist(n);
scanf("%d",&x);
checknode(head,x)? printf("Yes") : printf("No");
return 0;
}