I am making my own dictionary using templates (no I can't and I won't use anything from STL).
I want to have a very simple search function, but I have a small problem.
template <typename TElement>
void Dictionary<TElement>::search(TElement ADT, int key) { // Abstract Data Type
inf flag = 0;
index = int (key % max);
temp[index] = root[index]; // root of the hash
while (temp[index]->next != NULL) {
if(temp[index]->data->key_actual_name == key) { @things happen }
}
}
What I want to understand: how to use template so that I can have temp[index]->data-><template call>
if that makes any sense
I want to call the dictionary by using: Class_type == TElement and "key" is always an int but it can be different things. It might be an ID or phone number. Problem is I need to use the actual name of the key (if(temp[index]->data->ID (or phone or what ever) == key
) { @things happen }), I imagine I could use templates here but I don't know how.
also maybe relevant:
template <typename TElement>
typedef struct list{
TElement data;
struct list *next;
}node_type;
node_type *ptr[max], *root[max], *temp[max];
Also, if I do use a template for key_actual_name, how would the implementation work AND how would I call that function ?