-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hash_Search
80 lines (78 loc) · 1.26 KB
/
Hash_Search
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
#include<stdio.h>
struct node
{
int data;
struct node *link;
};
struct head
{
int count;
struct node *link;
};
void insert(struct head *heads,int x)
{
struct node *current=(struct node*)malloc(sizeof(struct node));
if(heads->count==0)
{
current->data=x;
current->link=NULL;
heads->link=current;
heads->count++;
}
else
{
current->data=x;
current->link=heads->link;
heads->link=current;
heads->count=heads->count+1;
}
}
void display(struct head *heads)
{
struct node *current=(struct node*)malloc(sizeof(struct node));
current=heads->link;
while(current!=NULL)
{
printf("%d\t",current->data);
current=current->link;
}
}
void search(struct head *heads,int x)
{ int y;
struct node *current=(struct node*)malloc(sizeof(struct node));
current=heads->link;
y=heads->count;
while(y>0)
{
if(current->data==x)
{printf("Found");
break;
}
else
{current=current->link;y--;}
}
}
void main()
{int n,i,x,y,se;
struct head *heads[5];
for(i=0;i<5;i++)
{
heads[i]=(struct head*)malloc(sizeof(struct head));
heads[i]->link=NULL;
heads[i]->count=0;
}
//struct node *node=(struct head*)malloc(sizeof(struct head));
clrscr();
printf("Enter the number ot element");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&x);
y=x%10;
insert(heads[y],x);
}
scanf("%d",&se);
y=se%5;
search(heads[y],se);
getch();
}