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

program

The document contains a C program that implements a simple hash table using linked lists for collision resolution. It includes functions for inserting, searching, deleting keys, and displaying the hash table. The main function demonstrates these operations by inserting several keys and then deleting one, followed by displaying the hash table before and after deletion.

Uploaded by

ot7sakshi
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)
2 views

program

The document contains a C program that implements a simple hash table using linked lists for collision resolution. It includes functions for inserting, searching, deleting keys, and displaying the hash table. The main function demonstrates these operations by inserting several keys and then deleting one, followed by displaying the hash table before and after deletion.

Uploaded by

ot7sakshi
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/ 6

#include<stdio.

h>

#include<stdlib.h>

Typedef struct node.

Int key;

Struct node *next;

NODE;

NODE HT [10]-(NULL);

Int hf(int key)

Return (key%10);

Void insert (int k)

Int index;
NODE *newnode NULL, *temp;

Newnode (NODE*)malloc(sizeof (NODE));

Newnode->key=k;

Newnode->next=NULL;

Index=hf (k);

If (HT [index]==NULL)

HT [index]=newnode;

Else

Temp-HT [index]; while (temp->next!=NULL)

Temp-temp->next;

Temp->next-newnode;

}
Void search (int key)

Int index;

NODE *temp;

Index-hf (key);

For (temp-HT[index]; temp!=NULL; temp-temp->next)

If (temp->key=-key)

Printf(“%d found”, key);

Return;

Printf(“%d not found”, key);

Void deleteKey (int key)

(
Int index;

NODE *temp;

Index-hf (key); temp-HT [index]; if ((temp!=NULL) && (temp->key=-key))


else

HT [index]=temp->next;

For (temp-HT[index]; temp!-NULL; temp-temp->next)

If (temp->next->key=-key)

Temp->next-temp->next->next;

Return;

Printf(“%d not found”, key);

1
}

Void showTable()

Inti, index;

NODE *temp;

For(i=0; i<10; i++)

Printf(“%d “, i);

For (temp-HT[1]; temp!=NULL; temp-temp->next)

Printf(“%d->”, temp->key);

Printf(“NULL\n”);

Void main()

Insert (80);

Insert (23);

Insert (34);

Insert (48);
Insert (73);

Insert (93);

Insert (78);

showTable();

deleteKey (73);

printf(“\nAfter deletion:\n”);

showTable();

You might also like