Skip to content

Commit 96c8838

Browse files
authored
Add files via upload
1 parent f543a82 commit 96c8838

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
struct Node
4+
{
5+
int data;
6+
struct Node* next;
7+
}*first =NULL;
8+
void create(int a[], int n)
9+
{
10+
int i;
11+
struct Node * t, * last;
12+
first = (struct Node*)malloc(sizeof(struct Node));
13+
first->data = a[0];
14+
first->data = NULL;
15+
last = first;
16+
for (i = 1; i < n; i++)
17+
{
18+
t = (struct Node*)malloc(sizeof(struct Node));
19+
t->data = a[i];
20+
t->next = NULL;
21+
last->next = t;
22+
last = t;
23+
24+
}
25+
26+
}
27+
struct Node* Lsearch(struct Node* p, int key)
28+
{
29+
while (p != NULL)
30+
{
31+
if (key == p->data)
32+
return p;
33+
p = p->next;
34+
}
35+
return NULL;
36+
}
37+
int main()
38+
{
39+
struct Node* temp;
40+
int a[] = { 1,2,3,4,5,8,9,7 };
41+
create(a,9);
42+
temp = Lsearch(first, 9);
43+
if (temp)
44+
{
45+
printf("Key is found %d", temp->data);
46+
47+
}
48+
else
49+
printf("Key not found !");
50+
return 0;
51+
52+
}

0 commit comments

Comments
 (0)