forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlsearchinLL.c
51 lines (46 loc) · 879 Bytes
/
lsearchinLL.c
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
48
49
50
51
#include<stdio.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node*next;
}node;
int main()
{
int n,i,t;
node *a,*head=NULL;
printf("Enter the number of nodes:");
scanf("%d",&n);
printf("\n Enter element of node:");
for(i=1;i<=n;i++)
{
if(head==NULL)
{
a=(node*)malloc(sizeof(node));
head=a;
scanf("%d",&head->data);
a->next=NULL;
}
else
{
a->next=(node*)malloc(sizeof(node));
a=a->next;
scanf("%d",&a->data);
a->next=NULL;
}
}
a=head;
int f,count=1;
printf("Enter the element you want to find:");
scanf("%d",&f);
while(a!=NULL)
{
if(f==a->data)
{ printf("element is found at block:%d",count);
break;
}
a=a->next;
count++;
}
return 0;
}