Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38ecd08

Browse files
authored
Merge pull request#78 from AnamikaSamanta/main
Linearprobing using C
2 parentsbc0fa57 +7b1d553 commit38ecd08

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

‎Linearprobing.C‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* Insert keys into an array with linear probing technique of collision resolution technique. */
2+
/* Data Structures Using C by UDIT AGARWAL */
3+
4+
#include<stdio.h>
5+
#include<conio.h>
6+
#defineMAX 10
7+
8+
inta[MAX];
9+
voidlp(int ,int[]);
10+
voidlpsr(intkey,inta[MAX]);
11+
voiddisplay(inta[MAX]);
12+
13+
voidmain()
14+
{
15+
inti,key,ch ;
16+
clrscr();
17+
for(i=0;i<MAX;i++)
18+
a[i]='\0';
19+
do{
20+
printf("\n\n Program for insertion/searching keys with linear probing ");
21+
printf("\n************************************************************\n\n");
22+
printf("\n 1. Insert keys ");
23+
printf("\n 2. Search key ");
24+
printf("\n 3. Display keys ");
25+
printf("\n 4. Exit ");
26+
printf("\n Select operation ");
27+
scanf("%d",&ch);
28+
switch(ch)
29+
{
30+
case1:do{
31+
printf("\n Enter key value [type -1 for termination] ");
32+
scanf("%d",&key);
33+
if (key!=-1)
34+
lp(key,a);
35+
}while(key!=-1);
36+
display(a);
37+
break;
38+
case2:printf("\n Enter search key value ");
39+
scanf("%d",&key);
40+
lpsr(key,a);
41+
break;
42+
case3:display(a);
43+
break;
44+
}
45+
}while(ch!=4);
46+
}
47+
48+
/* function lp find a location for key and insert it */
49+
voidlp(intkey,inta[MAX])
50+
{
51+
intloc;
52+
loc=key %MAX;
53+
while (a[loc]!='\0')
54+
loc=++loc %MAX;
55+
a[loc]=key;
56+
}
57+
58+
/* function lpsr find a location for a key */
59+
voidlpsr(intkey,inta[MAX])
60+
{
61+
intloc;
62+
loc=key %MAX;
63+
while ((a[loc]!=key)&& (a[loc]!='\0'))
64+
loc=++loc%MAX;
65+
if (a[loc]!='\0')
66+
printf("\n Search successful at index %d",loc);
67+
else
68+
printf("\n Search unsuccessful ");
69+
}
70+
71+
voiddisplay(inta[MAX])
72+
{
73+
inti;
74+
printf("\n List of keys ('0' indicate that the location is empty): \n");
75+
for (i=0;i<MAX;i++)
76+
printf(" %d ",a[i]);
77+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp