I downloaded liblcthw and tried to compile. Mostly I can compile, but for the calls to heapsort and mergesort in darray_algos.c
and darray_algos.h
. Search on google revealed these 2 are not part of the C-standard library. The question I am referring to is : https://stackoverflow.com/questions/23851098/c-compile-errors-learn-c-the-hard-way-ex-32.
The accepted answer has the following text:
The Exercise 32 code downloaded from the github repo is platform specific for a BSD system (and perhaps OS X). Specifically, there are a couple required symbols for a successful build that are present on a BSD sysem, but which are most likely not present on a (Linux) Ubuntu 12.04 system. These include:
mergesort
heapsortNevertheless, the library and unit tests can all be successfully compiled, with the exception of one unit test that (eventually) will require the above symbols. Moving the single problematic test from the tests directory will allow the other tests to compile on a (Linux) SuSE SLES 11 system, if a slight change is made to a flaw in the makefile shown below.
And it goes on to explain how to compile correctly.
I also searched the source file of the standard C library that my system implements (Fedora) and found only qsort there, not heapsort or mergesort.
Ofcourse removing the heapsort and mergesort is an option, but the heapsort
and mergesort
seem like reasonable choices, especially due to the attractive characteristics of heapsort and mergesort. So I set out to implement heapsort and see what roadbumps I came accross. I came across a few, especially the fact that we do not know what type we are sorting so I need a way to express an unknown type using its size into things like char *
. Most example program just assume and integer array, which simplifies everything (including comparison). The point is to also be able to sort any kind of object even a struct using a comparison function.
In order to get an idea how to do it I checked out the implementation of qsort in the Fedora implementation (probably related to or part of the gcc project). I found that it is complex and while I am writing this, I am trying to understand the code so I can tranlate this to an implementation of heapsort
. Still working on this.
In the meantime my question is: “Has anyone successfully implemented liblcthw and how did your do it?”.
Did you exclude heapsort and mergesort? Or did you find an implementation?