cLinkedList
A simple C library for doubly linked list creation and management
|
cLinkedList: A simple linked list manager for C/C++. More...
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include "../include/cLinkedList.h"
#include "../include/macrodef.h"
Go to the source code of this file.
Functions | |
unsigned long | cListLength (cLinkedList *myList) |
int | cListEmpty (cLinkedList *myList) |
cListElem * | cListFirstElem (cLinkedList *myList) |
Returns the first element of a linked list. | |
cListElem * | cListLastElem (cLinkedList *myList) |
Returns the last element of a linked list. | |
cListElem * | cListNextElem (cLinkedList *myList, cListElem *myElem) |
Returns the next element of a linked list when provided an element from the list. | |
cListElem * | cListPrevElem (cLinkedList *myList, cListElem *myElem) |
Returns the previous element of a linked list, when provided an element from the list. | |
cListElem * | cListFindElem (cLinkedList *myList, void *myData) |
Find an element in a linked list passed using the data linked in it. | |
void * | cListFindData (cLinkedList *myList, void *myData) |
Find a data point in a linked list if it is present. | |
void * | cListFirstData (cLinkedList *myList) |
Returns the first data point of a linked list. | |
void * | cListLastData (cLinkedList *myList) |
Returns the last data point of a linked list. | |
void * | cListNextData (cLinkedList *myList, void *myData) |
Returns the next data point of a linked list when provided a data point from the list. | |
void * | cListPrevData (cLinkedList *myList, void *myData) |
Returns the previous data point of a linked list, when provided a data point from the list. | |
int | cListInit (cLinkedList *myList) |
Initializes a doubly linked list. | |
int | cListInsertAfter (cLinkedList *myList, void *newData, cListElem *elem) |
Insert a data point into a linked list after an existing element in the list. | |
int | cListInsertBefore (cLinkedList *myList, void *newData, cListElem *elem) |
Insert a data point into a linked list before an existing element in the list. | |
int | cListAppend (cLinkedList *myList, void *newData) |
Append a data point into a linked list. | |
int | cListPrepend (cLinkedList *myList, void *newData) |
Prepend a data point into a linked list. | |
void | cListUnlinkElem (cLinkedList *myList, cListElem *delElem) |
Unlinks an element from a linked list. This does not remove the actual data point linked. | |
void | cListUnlinkAll (cLinkedList *myList) |
Unlinks all the elements from a linked list. This does not remove the actual data points linked. | |
void | cListUnlinkData (cLinkedList *delList, void *delData) |
Unlinks a data point that is linked in a linked list. | |
cLinkedList: A simple linked list manager for C/C++.
Definition in file cLinkedList.c.
int cListAppend | ( | cLinkedList * | myList, |
void * | newData | ||
) |
Append a data point into a linked list.
myList | Pointer to the cLinkedList linked list to which data needs to be linked. |
myData | Void pointer to the data point to be linked as an element into the linked list. |
Inserts the specified new data at the end of the supplied linked list as the last element.
myList | cLinkedList pointer to the linked list need to be used. |
newData | void pointer to the new data to be inserted. |
Definition at line 370 of file cLinkedList.c.
int cListEmpty | ( | cLinkedList * | myList | ) |
Returns 1 if a linked list is empty.
myList | Pointer to the cLinkedList linked list which needs to be checked. |
Checks to see if the cLinkedList linked list passed a parameter is empty.
myList | cLinkedList pointer of the linked list which we need to check if empty. |
Definition at line 43 of file cLinkedList.c.
void * cListFindData | ( | cLinkedList * | myList, |
void * | myData | ||
) |
Find a data point in a linked list if it is present.
myList | Pointer to the cLinkedList linked list being accessed. |
myElem | Pointer to the data being searched for. |
Attempts to find an element linked in a cLinkedList list using the data that would be held by the list element to be found. Returns a void pointer to the data found on the linked list. Returns a NULL pointer if the data isn't found. The longer the list, the longer it could take to find the element. This is a linear search.
myList | cLinkedList pointer to the linked list need to be read. |
myData | void pointer to the data that would be held by the list element that needs to be found. |
Definition at line 171 of file cLinkedList.c.
cListElem * cListFindElem | ( | cLinkedList * | myList, |
void * | myData | ||
) |
Find an element in a linked list passed using the data linked in it.
myList | Pointer to the cLinkedList linked list being accessed. |
myElem | Pointer to the data which is linked to the element being search for. |
Attempts to find an element linked in a cLinkedList list using the data that would be held by the list element to be found. Returns a cListElem pointer to the first element holding the data if the data is found in the list. Returns a NULL pointer if the data isn't found. The longer the list, the longer it could take to find the element. This is a linear search.
myList | cLinkedList pointer to the linked list need to be read. |
myData | void pointer to the data that would be held by the list element that needs to be found. |
Definition at line 145 of file cLinkedList.c.
void * cListFirstData | ( | cLinkedList * | myList | ) |
Returns the first data point of a linked list.
myList | Pointer to the cLinkedList linked list whose first data point is needed. |
Returns a pointer to the data held by the first element on the cLinkedList list. But, it returns a NULL pointer if the list is empty.
myList | cLinkedList pointer to the linked list need to be used. |
Definition at line 192 of file cLinkedList.c.
cListElem * cListFirstElem | ( | cLinkedList * | myList | ) |
Returns the first element of a linked list.
myList | Pointer to the cLinkedList linked list whose first element is needed. |
Returns a cListElem pointer to the first element on the linked list passed as a parameter. Returns a NULL pointer if the list is empty.
myList | cLinkedList pointer to the linked list whose first element we need. |
Definition at line 66 of file cLinkedList.c.
int cListInit | ( | cLinkedList * | myList | ) |
Initializes a doubly linked list.
myList | Pointer to the cLinkedList linked list which has already been created. |
Dynamically initialized the cLinkedList pointer with a linked list.
myList | cLinkedList pointer to the linked list need to be used. |
Definition at line 282 of file cLinkedList.c.
int cListInsertAfter | ( | cLinkedList * | myList, |
void * | newData, | ||
cListElem * | elem | ||
) |
Insert a data point into a linked list after an existing element in the list.
myList | Pointer to the cLinkedList linked list to which data needs to be linked. |
myData | Void pointer to the data point to be linked as an element into the linked list. |
myElem | Pointer to the cListElem element in the linked list after which the new data point needs to be inserted. |
Inserts the data element passed into the linked list specified as a list element after the specified list element.
myList | cLinkedList pointer to the linked list need to be used. |
newData | void pointer to the new data to be inserted. |
elem | cListElem pointer to the element next to which the new data needs to be inserted |
Definition at line 307 of file cLinkedList.c.
int cListInsertBefore | ( | cLinkedList * | myList, |
void * | newData, | ||
cListElem * | elem | ||
) |
Insert a data point into a linked list before an existing element in the list.
myList | Pointer to the cLinkedList linked list to which data needs to be linked. |
myData | Void pointer to the data point to be linked as an element into the linked list. |
myElem | Pointer to the cListElem element in the linked list before which the new data point needs to be inserted. |
Inserts the data element passed into the linked list specified as a list element before the specified list element.
myList | cLinkedList pointer to the linked list need to be used. |
newData | void pointer to the new data to be inserted. |
elem | cListElem pointer to the element before which the new data needs to be inserted |
Definition at line 339 of file cLinkedList.c.
void * cListLastData | ( | cLinkedList * | myList | ) |
Returns the last data point of a linked list.
myList | Pointer to the cLinkedList linked list whose last data point is needed. |
Returns a pointer to the data held by the last element on the cLinkedList list. But, it returns a NULL pointer if the list is empty.
myList | cLinkedList pointer to the linked list need to be used. |
Definition at line 213 of file cLinkedList.c.
cListElem * cListLastElem | ( | cLinkedList * | myList | ) |
Returns the last element of a linked list.
myList | Pointer to the cLinkedList linked list whose last element is needed. |
Returns a cListElem pointer to the last element of the linked list passed as a paramener. Returns a NULL pointer if the list is empty.
myList | cLinkedList pointer to the linked list whose last element we need. |
Definition at line 83 of file cLinkedList.c.
unsigned long cListLength | ( | cLinkedList * | myList | ) |
Returns the length of a linked list.
myList | cLinkedList pointer of the linked list whose length is returned. |
Returns the length of the cLinkedList linked list passed to it as a parameter.
myList | cLinkedList pointer of the linked list whose length is returned. |
Definition at line 27 of file cLinkedList.c.
void * cListNextData | ( | cLinkedList * | myList, |
void * | myData | ||
) |
Returns the next data point of a linked list when provided a data point from the list.
myList | Pointer to the cLinkedList linked list being accessed. |
myElem | Pointer to the data point in the list whose next data point is needed. |
Returns a pointer to the data next to the data on the cLinkedList list as passed to the function. But, it returns a NULL pointer if the list is empty or if the passed data does not exist.
myList | cLinkedList pointer to the linked list need to be used. |
myData | void pointer to the data next to which we get the want look for the next data. |
Definition at line 236 of file cLinkedList.c.
cListElem * cListNextElem | ( | cLinkedList * | myList, |
cListElem * | myElem | ||
) |
Returns the next element of a linked list when provided an element from the list.
myList | Pointer to the cLinkedList linked list being accessed. |
myElem | Pointer to the cListElem element in the list whose next element is needed. |
Returns a cListElem pointer to the element in a cLinkedList linked list that is next to and after another element. Returns a NULL pinter if the list is empty or the element being passed as a pointer is the last element.
myList | cLinkedList pointer to the linked list need to be read. |
myElem | The function returns the element next to the element pointed to by this cListElem pointer. |
Definition at line 101 of file cLinkedList.c.
int cListPrepend | ( | cLinkedList * | myList, |
void * | newData | ||
) |
Prepend a data point into a linked list.
myList | Pointer to the cLinkedList linked list to which data needs to be linked. |
myData | Void pointer to the data point to be linked as an element into the linked list. |
Inserts the specified new data at the beginning of the supplied linked list as the first element.
myList | cLinkedList pointer to the linked list need to be used. |
newData | void pointer to the new data to be inserted. |
Definition at line 383 of file cLinkedList.c.
void * cListPrevData | ( | cLinkedList * | myList, |
void * | myData | ||
) |
Returns the previous data point of a linked list, when provided a data point from the list.
myList | Pointer to the cLinkedList linked list being accessed. |
myElem | Pointer to the data point in the list whose previous data point is needed. |
Returns a pointer to the data before the data on the cLinkedList list as passed to the function. But, it returns a NULL pointer if the list is empty or if the passed data does not exist.
myList | cLinkedList pointer to the linked list need to be used. |
myData | void pointer to the data before which we look for the previous data. |
Definition at line 258 of file cLinkedList.c.
cListElem * cListPrevElem | ( | cLinkedList * | myList, |
cListElem * | myElem | ||
) |
Returns the previous element of a linked list, when provided an element from the list.
myList | Pointer to the cLinkedList linked list being accessed. |
myElem | Pointer to the cListElem element in the list whose previous element is needed. |
Returns a cListElem pointer to the element in a cLinkedList linked list that is before another element. Returns a NULL pinter if the list is empty or the element being passed as a pointer is the first element.
myList | cLinkedList pointer to the linked list need to be read. |
myElem | The function returns the element beefore the element pointed to by this cListElem pointer. |
Definition at line 122 of file cLinkedList.c.
void cListUnlinkAll | ( | cLinkedList * | myList | ) |
Unlinks all the elements from a linked list. This does not remove the actual data points linked.
myList | Pointer to the cLinkedList linked list which needs to be emptied out in full. |
Unlinks all elements from the linked list and empties the cLinkedList list. Calling this function before the end of the program ensure that the linked list does not leave any orphaned memory locations when the program exits.
myList | cLinkedList pointer to the linked list need to be used. |
Definition at line 424 of file cLinkedList.c.
void cListUnlinkData | ( | cLinkedList * | delList, |
void * | delData | ||
) |
Unlinks a data point that is linked in a linked list.
myList | Pointer to the cLinkedList linked list from which a data point needs to be unlinked. |
myData | Void pointer to the data point which needs to be unlinked from the linked list. |
Unlinks the first element in the list which holds the data pointed to by this pointer.
delList | cLinkedList pointer to the linked list need to be used. |
delData | void pointer to the data whose element needs to be unlinked from the list. |
Definition at line 443 of file cLinkedList.c.
void cListUnlinkElem | ( | cLinkedList * | myList, |
cListElem * | delElem | ||
) |
Unlinks an element from a linked list. This does not remove the actual data point linked.
myList | Pointer to the cLinkedList linked list from which an element needs to be unlinked. |
myElem | Pointer to the cListElem in the linked list that needs to be unlinked. |
Unlinks the element requested from the linked list if it exists in the linked list.
myList | cLinkedList pointer to the linked list need to be used. |
delElem | cListElem pointer to the element that needs to unlinked. |
Definition at line 397 of file cLinkedList.c.