Computer Science  >  Research Paper  >  Arizona State University - CS 412Lab_hash_2nd_revised.cpp (All)

Arizona State University - CS 412Lab_hash_2nd_revised.cpp

Document Content and Description Below

/* Hash Table: 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 tabl ... e (array). Define 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 <iomanip> using namespace std; const int SIZE = 27; // a good strong prime number const int EMPTY = -1; // -1 indicates that the cell is empty #define DISPLAY true // remove to disable debugging output struct hashrecord { int id; //to hold a unique id for each element int data; //the data for each element, I used a simple int }; class HashTable { private: hashrecord table[SIZE]; // where our data will be held public: HashTable(); int Hash(int data); bool Add(int data); bool Probe(int data); int Lookup(int data); void Print(); }; HashTable::HashTable() { #ifdef DISPLAY cout << "Building hash table.\n"; #endif for (int i = 0; i < SIZE; i++) // table[i] = EMPTY; { table[i].id = -1; //set all ids to -1 to show they're empty table[i].data = EMPTY; //set all data values to default } } //This function returns the modulo of that int by the size of the table (array). int HashTable::Hash(int data) { return data % SIZE; } /* add items in the table. - 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. */ bool HashTable::Add(int data) [Show More]

Last updated: 3 years ago

Preview 1 out of 7 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of Arizona State University - CS 412Lab_hash_2nd_revised.cpp document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Also available in bundle (1)

Click Below to Access Bundle(s)

Hash

Hash LAB

By Muchiri 4 years ago

$11

2  

Reviews( 0 )

$9.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

118
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 21, 2021

Number of pages

7

Written in

All

Seller


Profile illustration for Muchiri
Muchiri

Member since 4 years

209 Documents Sold

Reviews Received
19
5
1
1
6
Additional information

This document has been written for:

Uploaded

Apr 21, 2021

Downloads

 0

Views

 118

Document Keyword Tags

Recommended For You

Get more on Research Paper »

$9.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·