How to implement an associative data structure of an array / map / hash table (in general and in C ++)

Well, I’m making a small phonebook application, and I decided that using maps would be a better data structure, but I don’t know where to start. (Gotta implement a data structure from scratch - school work)

+3
source share
3 answers

Tries are pretty effective for implementing maps where keys are short strings. The Wikipedia article explains this pretty well.

To deal with duplicates, just make each node of the tree a repository of a linked list of duplicate matches

Here is the basic structure for trie

struct Trie {
   struct Trie* letter;
   struct List *matches;
};

malloc (26 * sizeof (struct Trie)) , . , .

, , , struct List .

+5

, - . , . , . , .

+2

: , .

( / ), -. : , , - -, . , , ( , : -)).

, , ( ): , , .

, , : -)

+2
source

Source: https://habr.com/ru/post/1729360/


All Articles