-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchSLL.cpp
83 lines (83 loc) · 1.38 KB
/
SearchSLL.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
struct node
{
int data;
struct node *link;
}*temp,*head,*newnode;
CreateLL()
{
head = 0;
int choice = 1;
while(choice)
{
newnode = (struct node*)malloc(sizeof(struct node));
printf("Enter data : ");
scanf("%d",&newnode->data);
newnode->link = 0;
if(head == 0)
{
head = temp = newnode;
}
else
{
temp->link = newnode;
temp = newnode;
}
printf("Do you want to continue 0/1 ?");
scanf("%d",&choice);
if(choice==1)
{
continue;
}
else
{
break;
}
}
}
Display()
{
int count=0;
temp = head;
printf("\nList is : ");
while(temp!=0)
{
printf("%d->",temp->data);
temp = temp->link;
count++;
}
printf("NULL");
printf("\nTotal no. of nodes : %d",count);
}
Searching()
{
struct node*temp;
int num,cho=1,coun=1;
temp=head;
while(cho==1)
{
printf("\nWhich Element You Want to Search : ");
scanf("%d",&num);
printf("element is : %d",num);
while(temp!=0)
{
if(temp->data==num)
{
printf("\nSuccess'~'\nElement is found at Position :%d",coun);
}
temp=temp->link;
coun++;
}
printf("\nDo You want to Search any Element 0/1 : ");
scanf("%d",&cho);
}
}
int main()
{
CreateLL();
Display();
Searching();
return 0;
}