-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchCLL.cpp
85 lines (84 loc) · 1.4 KB
/
SearchCLL.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
84
85
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*head;
void CreateCLL()
{
struct node*temp,*newnode;
int choice = 1;
printf("Create a circular linklist ^~^\n");
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data : ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head = temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
temp->next=head;
printf("Do U want to continue 1/0 : ");
scanf("%d",&choice);
}
}
Display()
{
struct node*temp,*newnode;
int count=1;
if(head==0)
{
printf("\nList is Empty *~* ");
}
else
{
temp=head;
printf("\nCreated Circular Linklist : ");
while(temp->next!=head)
{
printf("%d->",temp->data);
temp = temp->next;
count++;
}
printf("%d",temp->data);
}
}
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);
break;
}
temp=temp->next;
coun++;
}
printf("\nDo You want to Search any Element 0/1 : ");
scanf("%d",&cho);
}
}
int main()
{
CreateCLL();
Display();
Searching();
return 0;
}