mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
2314a19586
The trie example had some issues; * It did not follow the code convention in CONTRIBUTING.md * The createTrieNode used an inefficient zeroing method (looping over the entries) which also does not zero out holes in the structure (e.g. an alternative would be to use "*node = &(TrieNode){0}", but calloc does all that anyway * It used an inefficient and clumsy printArray method * It used strlen inside the algorithm; this new method could get rid of any strlen/strnlen usage (inserts/searches could be sanitized by snprintf) * This version can allow for a custom mapping function, e.g. if NULL is a valid separator (say that you want a trie for certain binary packages) * The previous version actually contained out-of-bounds array indexing; there were no checks for out-of-bound indexing and words in the word list did contain out of bounds words. It's a surprise it was working so well. * This version just returns 'int' to allow for error checks (instead of a printf inside the algorithm), and uses double pointers for return values (good practice) * The usage example contained unnecessary mallocs, switched that out for scanf. The example is just an example after all, in real applications you'd have better input sanitazion. |
||
---|---|---|
.. | ||
array | ||
binary_trees | ||
dictionary | ||
dynamic_array | ||
graphs | ||
hash_set | ||
heap | ||
linked_list | ||
list | ||
queue | ||
stack | ||
trie | ||
stack.c |