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: 3 years ago
Preview 1 out of 5 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Hash LAB
By Muchiri 4 years ago
$11
2
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Apr 21, 2021
Number of pages
5
Written in
All
This document has been written for:
Uploaded
Apr 21, 2021
Downloads
0
Views
102
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·