Programmer's library for manupulate Single Linked List
Prototypes of functions in
sllist.h
Code of functions in
sllist.cpp
Example without the library
withoutSLL.cppExamples of uses in
main.cpp
User functions prototypes in
myFuncts.hCode in
myFuncts.cpp
Conform to g++
Building
makeThis command produce test executable
./testSLLCleaning
make mrproperReturns a pointer to a new, empty list. If allocation fails, returns nullptr.
sllist* sllist_create(void)Frees the memory of the list struct and all associated nodes.
void sllist_destroy(sllist* theIdx)Adds a node to the front of the list. If allocation fails, returns -1, otherwise returns 0.
int sllist_push_front(sllist* theIdx, void* theData)Adds a node to the end of the list. If allocation fails, returns -1, otherwise returns 0.
int sllist_push_back(sllist* theIdx, void* theData)Remove the first node from the linked list, save a pointer to the data, free the node (but do not free the data itself), and return a pointer to the data so that it can be used. If the list is empty, returns nullptr.
void* sllist_pop_front(sllist* theIdx)Remove the last node from the linked list, save a pointer to the data, free the node (but do not free the data itself), and return a pointer to the data so that it can be used. If the list is empty, returns nullptr.
void* sllist_pop_back(sllist* theIdx)Changes the current node to the node after the current node. Returns 1 if the current node is nullptr.
int sllist_step(sllist* theIdx)Returns a pointer to the payload of the node at the location specified by the passed index value. The passed index value is interpreted as an offset from index zero, the first node of the list. Returns nullptr if the list is empty or the index is out of range.
void* sllist_read_index(sllist* theIdx, int theRow)Adds a node after the passed node. If allocation fails, returns -1. If the node doesn't exist in the list, returns 1. Otherwise, returns 0.
int sllist_insert_after(sllist* theIdx, int theRow, void* theData)Remove the specified node from the linked list, save a pointer to the data, free the node (but do not free the data itself), and return a pointer to the data so that it can be used. If the list is empty or the node doesn't exist in the list, returns nullptr. Attempting to extract after the tail will also return nullptr.
void* sllist_extract_after(sllist* myIdx, int theRow)Very largely inspired by a "code review" on StackExchange.