0% found this document useful (0 votes)
3 views

Hash Table

Uploaded by

adilshanu23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Hash Table

Uploaded by

adilshanu23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Hash table

#include<stdio.h>

#define size 7

int arr[size];

void init()

int i;

for(i = 0; i < size; i++)

arr[i] = -1;

void insert(int value)

int key = value % size;

if(arr[key] == -1)

arr[key] = value;

printf("%d inserted at arr[%d]\n", value,key);

else

printf("Collision : arr[%d] has element %d already!\n",key,arr[key]);

printf("Unable to insert %d\n",value);

void del(int value)

int key = value % size;

if(arr[key] == value)

arr[key] = -1;

else
printf("%d not present in the hash table\n",value);

void search(int value)

int key = value % size;

if(arr[key] == value)

printf("Search Found\n");

else

printf("Search Not Found\n");

void print()

int i;

for(i = 0; i < size; i++)

printf("arr[%d] = %d\n",i,arr[i]);

int main()

init();

insert(10); //key = 10 % 7 ==> 3

insert(4); //key = 4 % 7 ==> 4

insert(2); //key = 2 % 7 ==> 2

insert(3); //key = 3 % 7 ==> 3 (collision)

printf("Hash table\n");

print();

printf("\n");

printf("Deleting value 10..\n");

del(10);

printf("After the deletion hash table\n");

print();
printf("\n");

printf("Deleting value 5..\n");

del(5);

printf("After the deletion hash table\n");

print();

printf("\n");

printf("Searching value 4..\n");

search(4);

printf("Searching value 10..\n");

search(10);

return 0;

You might also like