The document provides code to implement a circular doubly linked list with a hash table. It includes code for a main function that provides a menu to insert, search, delete elements from the hash table. It also includes code for a HashNode struct and HashMap class with functions to insert, remove and search elements from the hash table by key. The code separates the implementation into main.cpp, header.h and implement.cpp files as requested.
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
1. (C++ exercise) 3. Implement a circular, doubly linked list with
a hash table implementation. Don’t use header and trailer nodes
in the list, as those nodes were supplied only for easy removal
of the first and last nodes from a non-circular list; the first and
last nodes didn’t need to be considered as special cases. In a
circular list, there aren’t any first and last nodes, so this is not a
problem. Be careful about the way you insert nodes, so that an
exact physical copy of the hash table is made in the copy
constructor and overloaded assignment operator.
P/S: please seperate the main.cpp, header file and implement
file like this pattern as shown below: ( Thanks for helping me
and I really do appriciate it!)
main.cpp
Code
header.h
Code
implement.cpp
Code
Solution
Main.cpp
int main()
{
My_Hash_Map hash;
int my_key, my_value;
int choice;
2. while (1)
{
cout<<"My Operations on Hash Table"<<" ";
cout<<"1.Insert Menu"<<" ";
cout<<"2.Search "<<" ";
cout<<"3.Delete"<<" ";
cout<<"4.Exit"<<" ";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter insert element ";
cin>>my_value;
cout<<"Enter my_key ";
cin>>my_key;
hash.insert(my_key, my_value);
break;
case 2:
cout<<"Enter Search element: ";
cin>>my_key;
hash.get(my_key);
break;
case 3:
cout<<"Enter my_key of the element to be deleted: ";
3. cin>>my_key;
hash.remove(my_key);
break;
case 4:
exit(1);
default:
cout<<" Please enter correct option ";
}
}
return 0;
}
Implement.cpp
struct My_Hash_Node
{
int data, key;
My_Hash_Node *next;
My_Hash_Node *prev;
};
class My_Hash_Map
{
public:
My_Hash_Node **my_htable, **my_table_top;
My_Hash_Map()
{
my_htable = new My_Hash_Node*[TABLE_SIZE];
4. my_table_top = new My_Hash_Node*[TABLE_SIZE];
for (int i = 0; i < TABLE_SIZE; i++)
{
my_htable[i] = NULL;
my_table_top[i] = NULL;
}
}
~My_Hash_Map()
{
delete [] my_htable;
}
int HashFunc(int key)
{
return key % TABLE_SIZE;
}
void insert(int key, int value)
{
int hash_val = HashFunc(key);
My_Hash_Node *entry = my_htable[hash_val];
if (entry == NULL)
{
entry = new My_Hash_Node;