Hash Table - Lab 1
Objective
Implement a simple hash table to manage student records. Each student record should contain a student ID (integer) and a name (string). You will use separate chaining to handle collisions.
Requirements:
Student Class: Create a class named
Student
that will store the student ID and name.HashNode Class: Create a class named
HashNode
to represent a node in the hash table. It should contain aStudent
object and a pointer to the next node.HashTable Class: Create a class named
HashTable
to implement the hash table with the following functionalities:Constructor: Initialize the hash table with a given size (e.g., 13).
Destructor: Deallocate the dynamically allocated memory.
Insert: Insert a new student record into the table.
Search: Search for a student record by student ID.
Remove: Remove a student record by student ID.
Print: Print all the student records in the hash table.
Functions to Implement:
int hashFunction(int key)
: Compute the hash index for a given key.void insert(int key, string name)
: Insert a new student record into the table.string search(int key)
: Search for a student record by student ID and return the name.void remove(int key)
: Remove a student record by student ID.void print()
: Print all student records in the table.
Guidelines:
Use C++ Standard Library's
std::vector
to represent the table.Implement separate chaining to handle collisions (using linked lists).
Example Usage:
HashTable table(13);
table.insert(12345, "Alice");
table.insert(67890, "Bob");
cout << table.search(12345); // Output: Alice
table.remove(12345);
cout << table.search(12345); // Output: Not found
table.print(); // Output: All remaining students in the hash table
Deliverable
Upload the following:
Full source code (.cpp files or .txt files)
Screenshot of the Console with the code executing
2024 - Programming 3 / Data Structures - Author: Dr. Kevin Roark