-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp6.c
More file actions
64 lines (62 loc) · 1011 Bytes
/
p6.c
File metadata and controls
64 lines (62 loc) · 1011 Bytes
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
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
int *ht,c,n,m,flag;
void create()
{
int i;
ht=(int*)malloc(m*sizeof(int));
if(ht==NULL&&m==0)
{
printf("the hash table is not present\n");
}
for(i=0;i<m;i++)
ht[i]=-1;
}
void display()
{
int i;
printf("the hash table is\n");
for(i=0;i<m;i++)
{
printf("%d-%d",ht[i],i);
}
}
void insert(int key)
{
int j;
j=key%m;
while(ht[j]!=-1)
{
j=(j+1)%m;
flag=-1;
}
if(flag)
{
printf("collosion occurs\n");
flag=0;
}
ht[j]=key;
display();
c++;
}
void main()
{
int i,key;
printf("enter the elements\n");
scanf("%d",&n);
printf("enter the memory size\n");
scanf("%d",&m);
create();
for(i=0;i<n;i++)
{
if(c!=m)
{
printf("enter the key\n");
scanf("%d",&key);
insert(key);
}
else
printf("the hash table is full\n");
}
}