-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearching_sll.c
More file actions
67 lines (67 loc) · 1.12 KB
/
searching_sll.c
File metadata and controls
67 lines (67 loc) · 1.12 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node * next;
};
typedef struct node* nodep;
nodep create();
nodep add();
void search_node_value(nodep);
int main()
{
nodep t,start;
t=add();
search_node_value(t);
getch();
return 0;
}
nodep create()
{
nodep t;
t=(nodep)malloc(sizeof(struct node));
if(t==NULL)
{
printf("stack overflow");
exit(0);
}
t->next=NULL;
printf("enter data\n");
scanf("%d",&t->info);
return t;
}
nodep add()
{
char ch;
nodep t,t1,start=NULL;
do{
t=create();
if(start==NULL)
start=t;
else
t1->next=t;
t1=t;
printf("Do you want to add more(y/Y):");
scanf(" %c",&ch);
}while(ch=='y' || ch=='Y');
return start;
}
void search_node_value(nodep start)
{
nodep temp;
int n,count=1;
printf("Enter the data to search in the list\n");
scanf("%d",&n);
temp=start;
while(temp!=NULL && n!=temp->info)
{
temp=temp->next;
count++;
}
if(temp!=NULL)
printf("%d found at position %d",n,count);
else
printf("%d not found",n);
}