-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_probing.c
More file actions
123 lines (85 loc) · 1.61 KB
/
linear_probing.c
File metadata and controls
123 lines (85 loc) · 1.61 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#define size 7
int a[size];
void insert(int data){
int h = data % size;
int h1;
int h2 = 0;
if(a[h] ==0){
a[h] = data;
}
else{
h1 = h;
int i;
for(i = 1;i<size;i++){
h2 =((h1 + i) % size );
if(a[h2]==0){
a[h2] = data;
break;
}
}
}
}
void display(){
printf("Array elements are:\n");
int i;
for(i=0;i<size;i++){
printf("%5d%5d",i,a[i]);
printf("\n");
}
}
int main() {
int data;
int ch;
int count=0;
for (int i = 0; i<size;i++){
a[i]=NULL;
}
printf("1.Insert 2.Display 3.Exit\n");
while(1){
printf("enter choice:");
scanf("%d",&ch);
switch(ch){
case 1:printf("enter data:");
scanf("%d",&data);
count = count + 1;
if (count>size){
printf("size exceeded\n");
}
else{
insert(data);
}
break;
case 2:display();
break;
case 3: exit(0);
}
}
return 0;
}
output:
1.Insert 2.Display 3.Exit
enter choice:1
enter data:50
enter choice:1
enter data:700
enter choice:1
enter data:76
enter choice:1
enter data:85
enter choice:1
enter data:92
enter choice:1
enter data:73
enter choice:1
enter data:101
enter choice:2
Array elements are:
0 700
1 50
2 85
3 92
4 73
5 101
6 76
enter choice:3