Computer Science > Research Paper > Irvine Valley College - CS 41Source_Hash_Table.cpp (All)
/* Create a hash table class/struct. Define an array that holds 27 elements. Define a function called Hash(int) -This function returns the modulo of that int by the size of the table (array). Def... ine an add function that takes an integer. -This function takes the integer, determines the hash of that number by calling the above hash function, then adds it to the table using linear probing for collision resolution. Define a function that looks up a value, it takes an integer, return -1 if the value is not in the table. Create a main that allows the user to add and lookup items in the table. */ #include <iostream> #include <string> using namespace std; // Declare the struct struct element { int info; element* next; }; // the size of the hash table followed by a linked list struct HashTable { private: const static int Tablesize = 27; // Define an array that holds 27 elements. element* ElementArea[Tablesize]; // elements in the hash table public: void initialization(); unsigned int Hash(int); void add(int); int search(int); }; void HashTable :: initialization() { for(int i = 0; i < Tablesize; i++) { ElementArea[i] = new element; ElementArea[i]->info = -999; // represents that the element area is empty ElementArea[i]->next = NULL; } } // hash function, returns an unsigned integer unsigned int HashTable:: Hash(int a) { return a % Tablesize; } void HashTable :: add(int inputvalue) [Show More]
Last updated: 1 year ago
Preview 1 out of 5 pages
Hash LAB
By Muchiri 3 years ago
$11
2
Connected school, study & course
About the document
Uploaded On
Apr 21, 2021
Number of pages
5
Written in
This document has been written for:
Uploaded
Apr 21, 2021
Downloads
0
Views
54
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·