This is a simple linked list manager for C that I've been using for a long while now. It may not be as optimized as Boost's libraries for linked lists, but it is very simple to use and has been tested rigorously.
This library allows you to dynamically create and manage doubly linked lists of elements that already exist in memory using pointers. This means that the actual data is untouched by this library which essentially manages a linked list of pointers to data.
In addition to the source, you can download cLinkedList
as a precompiled library. It is currently only available as a static library for 64-bit Windows, but I will make a DLL available when I have a time away from academics.
At some point, I will also build shared and static libraries for 64-bit PC Linux.
Download the repo and place it in your project directory. Be sure to add the include
directory along with either the bin/msvc/Win32/
or bin/msvc/x64/
directory to your compile and linker paths respectively. You do not need the source
and cLinkedList
directories, both of which can be safely removed.
Doxygen documentation for each of the functionalities below are linked with the functions. The Doxygen documentation home page is here.
- Initialize a linked list in dynamic memory (cListInit).
- Insert a data item AFTER an existing linked list element (cListInsertAfter).
- Insert a data item BEFORE an existing linked list element (cListInsertBefore).
- Append a data item to the end of a linked list (cListAppend).
- Prepend a data item to the start of the linked list (cListPrepend).
- Get the first list element/data item of a linked list (cListFirstElem/cListFirstData).
- Get the last list element/data item of a linked list (cListLastElem/cListLastData).
- Find the next list element/data item to a specific element of a linked list (cListNextElem/cListNextData).
- Find the previous list element/data item to a specific element of a linked list (cListPrevElem/cListPrevData).
- Find the list element associated with a particular data item, if linked (cListFindElem).
- Find the data item in a list if it has been linked (cListFindData).
- Get the length of the linked list (cListLength).
- Is the linked list empty? (cListEmpty)
- Unlink a particular list element in a linked list (cListUnlinkElem).
- Unlink a list element pointing to specific data item in a linked list (cListUnlinkData).
- Unlink all list elements from a linked list (cListUnlinkAll).
This library is considered feature-complete for my purposes. If you see any bugs or want a feature implemented, please don't hesitate to open an issue or send pull request my way.
POINTERS POINTERS POINTERS! First and foremost, creating this library was an exercise in the correct usage of C pointers. Additionally, this library gave the opportunity to write code that completely platform-agnostic and portable. With only one header and only one source file, it is easy to compile together with your other C/C++ code.
This library and its source code is distributed under the Mozilla Public License v2.0.