Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Thursday 24 October 2013

[C Program] to implement Hash Table

//Program to implement hash table.
#include<stdio.h>
#include<conio.h>
int hash[11][2] ;
void main()
{
int k,m=7,i,j,ch,v,h;
clrscr();
printf ("1.Insert 2.Retrive 3.Display 4.Exit") ;
do
{
printf("\n\nEnter choice:");
scanf("%d",&ch);
switch (ch)
{
case 1: printf("\nEnter key & value:");
scanf("%d %d",&k,&v);
h=k%m;
while(hash[h][1]!=0)
{
h=(h+1)%m;
}
hash[h][0]=k;
hash[h][1]=v;
break;
case 2: printf("\n\nEnter key:");
scanf("%d",&k);
h=k%m;
printf("\n\nValue:%d",hash[h][1]) ;
break;
case 3: printf("\nYour Hash Table:\n\n");
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",hash[i][j]);
}
printf("\n\n");
}
printf("\n");
break;
case 4: exit(0);
}
}while(ch<5);
getch();
}

/*Output:

1.Insert 2.Retrive 3.Display 4.Exit

Enter choice:1

Enter key & value:8 101

Enter choice:1

Enter key & value:1 103

Enter choice:1

Enter key & value:10 105

Enter choice:1

Enter key & value:13 107

Enter choice:1

Enter key & value:9 108

Enter choice:3

Your Hash Table:

0       0

8       101

1       103

10      105

9       108

0       0

13      107

0       0

0       0

0       0

Enter choice:2

Enter key:1

Value:101

Enter choice:4*/
Share it Please

Pankaj Gaikar

Pankaj Gaikar is a professional blogger from Pune, India who writes on Technology, Android, Gadgets, social media and latest tech updates at Punk Tech , Being Android & Shake The Tech . Email me HERE

0 comments :

Post a Comment

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine