The call to realloc() already frees the previously allocated memory if necessary.
By the man page of realloc(): "f the area pointed to was moved, a free(ptr) is done.",
and free(): "If free(ptr) has already been called before, undefined behavior occurs.".
* updating DIRECTORY.md
* chore: use the scripts repository for...
...the `DIRECTORY.md` workflow. The code is much shorter now as well.
* updating DIRECTORY.md
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
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.
Merge sort does not work properly. To reproduce the bug input 6, 5, 4, 3, 2, 1 the output would be 2, 3, 1, 4, 5, 6.
Co-authored-by: David Leal <halfpacho@gmail.com>
* perf: faster implementation of the TwoSum problem
* doc: fixed typos on comments
* updating DIRECTORY.md
* fix: comments on includes. Doxygen file. static test function
* fix: revert 1.c
* updating DIRECTORY.md
* fix: 0 files are not in one and only one directory
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* perf: faster implementation of the TwoSum problem
* doc: fixed typos on comments
* updating DIRECTORY.md
* fix: comments on includes. Doxygen file. static test function
* fix: #898 revert the nodir_files check version prior 2c86fbb
* fix: revert 1.c changes
* Apply suggestions from code review
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
* perf: faster implementation of the TwoSum problem
* doc: fixed typos on comments
* updating DIRECTORY.md
* fix: comments on includes. Doxygen file. static test function
* fix: #898 awesome-workflow: 1 files are not in one and only one directory
* fix: revert 1.c changes
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>