Witam serdecznie, mam zadanie na studiach z tablicy mieszającej, tzn. muszę napisać implementacje tablicy dynamicznej list. Nie mam pojęcia jak i w którym miejscu stworzyć listę, czy w ogóle składnia jest dobra i jak w późniejszych etapach się do tego odwoływać. Na ten czas mam takie coś, dodam że klasę listy tablicy mam z poprzednich zajęć i jeżeli jest to potrzebne to również mogę podać kod. Docelowo tablica musi mieć listy z węzłami posiadającymi klucz i wartość
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
template <typename T>
class hash_node
{
public:
string key;
T data;
hash_node* next;
hash_node* prev;
hash_node(string key, T data)
{
this->data = data;
this->key = key;
}
};
template <typename T>
class hash_list
{
public:
hash_node<T>* head=NULL;
hash_node<T>* tail=NULL;
int size;
T add_node(string key,T data)
{
hash_node<T>* node = new hash_node<T>(key,data);
if (size > 0)
{
tail->next = node;
node->prev = tail;
tail = node;
}
else
{
head = node;
tail = node;
}
size++;
}
};
template <typename T>
class hash_table
{
public:
T* array;
int current_size;
int max_size;
hash_table()
{
current_size = 0;
max_size = 1;
array = new T[max_size];
}
void add(string key, T data)
{
int index = hash(key);
if (current_size < max_size*0.75)
{
¿qué?
}
else
{
}
}
int search(string key)
{
}
int delete_key(string key)
{
}
void delete_all()
{
}
void show_all()
{
}
int hash(string key)
{
int index = 0;
int length = key.length();
for (int i = 0; i < length; i++)
{
int power = length - i - 1;
index = index + key[i] * pow(31, power);
}
index = index % max_size;
return abs(index);
}
void rehash()
{
}
};
int main()
{
hash_table < int >* ht = new hash_table < int >();
ht->add("asd", 15);
}