I added insertion sort into stdlib (and made stdlib a common library for all c files to access). I also included thorough tests that demonstrate the type-agnostic approach (which C uses to implement qsort and heapsort). This function is useful in the issue #30 (Mallocation) because a small number of structures need to be sorted in-place.
Type of change
[x] New feature (non-breaking change which adds functionality)
[ ] Bug fix (non-breaking change which fixes an issue)
Testing
I created tests for sorting arrays of integers, and custom type Type which includes an int, float, and char. These two types of arrays have their own compar function which compares two elements and returns an int of -1, 0, 1 indicating the intended order. The test then sorts the arrays, and checks that the corresponding array follows the compar function ordering, and has the same elements as is expected.
Test Configuration:
Hardware
OS
Checklist:
[x] I have performed a self-review of my code
[x] I have commented my code, particularly in hard-to-understand areas
[ ] I have made corresponding changes to the documentation
Description
I added insertion sort into stdlib (and made stdlib a common library for all c files to access). I also included thorough tests that demonstrate the type-agnostic approach (which C uses to implement qsort and heapsort). This function is useful in the issue #30 (Mallocation) because a small number of structures need to be sorted in-place.
Type of change
Testing
I created tests for sorting arrays of integers, and custom type
Type
which includes an int, float, and char. These two types of arrays have their owncompar
function which compares two elements and returns anint
of-1, 0, 1
indicating the intended order. The test then sorts the arrays, and checks that the corresponding array follows thecompar
function ordering, and has the same elements as is expected.Test Configuration:
Checklist: