0% found this document useful (0 votes)
5 views4 pages

C Program for Linear Search in Linked List

The document describes implementing a linear search on a linked list in C. It includes the code to create a linked list with nodes containing data and pointers, a search function that iterates through the list comparing the search item to the data in each node, and a main function that tests it by creating a sample linked list and searching for an element.

Uploaded by

Shubham Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

C Program for Linear Search in Linked List

The document describes implementing a linear search on a linked list in C. It includes the code to create a linked list with nodes containing data and pointers, a search function that iterates through the list comparing the search item to the data in each node, and a main function that tests it by creating a sample linked list and searching for an element.

Uploaded by

Shubham Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

rognam24

WAP in C to implement Linear Search using Linked Lis

nclude Stdio. h>


include<malloc. h
Struct node

nt data
Struct node next

irst nN
int Search (int item

int Count
n & -first
while nwnext= NULL)

i(nw data = item)

Dreak
else
Count t+,
w nw next

retoryn Count

int main )
int no, , tem, pos
irst. next NULL

8Cirst
hodes you want
n lnked t :")
printf (M Ho many

Scanf C2 d", g no) s

printf (n")
for (t o, t< ho; ir+)

rode)
ho- next (Struct node) malloc(sizeof(struct
printf ("Enier element in node ,d i+1),
Scanf (%d", mw data)
nwhu next

nw hext NULL
in linked List: mn");
print C /n Element
nw: fist
ohile ( nus nert= NULL

printf Cd \t", nw- dala)


no nd ext;

print(w');
printf n Enter element to be Searchtd)
Stanf7dy item)
poS Search (tem)
f pos & no)
printt (w' 7.d is fouond ot node 7. d',item, pos)
else
printf CSorry7dis not in linked li'st ", iten)
felurn D,
0utbot
How many nodes you want n linked list ?: 6
Enter element in
node : 5
Enter element in node 2 9
Enter element in node 3 :
88
Enter element in node4 21
Enter element in node. 5: 6
Enter element in node 6:
86
Elements in inked List
88
Enter element
86
o be
Searche d: 27
21 s found at node 4

You might also like