. Hash table will have 'n' number of buckets. To insert a node into the hash table, we need to find the hash index for the given key. And it could be calculated using the hash function. Example: hashIndex = key% noOfBuckets. Move to the bucket corresponds to the above calculated hash index and insert the new node at the end of the list.
Give More Feedback
To delete a node from hash table, get the key from the user, calculate the hash index, move to the bucket corresponds to the calculated hash index, search the list in the current bucket to find and remove the node with the given key. Finally, remove the node with given key, if it is present. Hash table with 5 buckets. 0, 1,2,3 and 4 are the hash indexes +-+ 0 +-+ 1 +-+ 2 +-+ 3 +-+ 4 +-+ Insert a node with key 33 into the hash table. HashIndex = 33% 5(no of buckets) hashIndex = 3 Hash index is 3. So, insert the new node to the bucket with hash index 3.
+-+ 0 +-+ - - 1 - 21 data - - 31 data - -X +-+ - - 2 +-+ - 3 - 33 data -X +-+ - 4 +-+ Delete a node with key 31 from the hash table. HashIndex = 31% 5(no of buckets) = 1 Move to the bucket with above calculated hash index(1), search the list in the current bucket(bucket with index 1)to find the node with given key and delete it.
C Program To Implement Dictionary Using Hashing Output
+-+ 0 +-+ - 1 - 21 data - -X +-+ - 2 +-+ - 3 - 33 data -X +-+ - 4 +-+. Jp@jp-VirtualBox:$./a.out Enter the number of elements:3 1. Exit Enter your choice:1 Enter the key value:3 Name:Sally Age:23 1. Exit Enter your choice:1 Enter the key value:33 Name:Harry Age:25 1. Exit Enter your choice:1 Enter the key value:7 Name:Nick Age:30 1. Exit Enter your choice:1 Enter the key value:35 Name:Raj Age:28 1.
See More On Stackoverflow
Exit Enter your choice:4 Data at index 0 in Hash Table: VoterID Name Age - 33 Harry 25 3 Sally 23 Data at index 1 in Hash Table: VoterID Name Age - 7 Nick 30 Data at index 2 in Hash Table: VoterID Name Age - 35 Raj 28 1. Exit Enter your choice:2 Enter the key to perform deletion:33 Data deleted successfully from Hash Table 1. Exit Enter your choice:4 Data at index 0 in Hash Table: VoterID Name Age - 3 Sally 23 Data at index 1 in Hash Table: VoterID Name Age - 7 Nick 30 Data at index 2 in Hash Table: VoterID Name Age - 35 Raj 28 1. Neurosolutions center. Exit Enter your choice:3 Enter the key to search:35 VoterID: 35 Name: Raj Age: 28 1. Exit Enter your choice:5.
Books.google.com.tr - An effective blend of carefully explained theory and practical applications, this text imparts the fundamentals of both information theory and data compression. Lineage 1 bot program download. Although the two topics are related, this unique text allows either topic to be presented independently, and it was specifically designed so. Introduction to Information Theory and Data Compression, Second Edition.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |