cLinkedList
A simple C library for doubly linked list creation and management
Loading...
Searching...
No Matches
cLinkedList.h File Reference

cLinkedList: A simple linked list manager for C/C++. More...

#include <stddef.h>
#include "macrodef.h"

Go to the source code of this file.

Data Structures

struct  _cListElem
 
struct  _cLinkedList
 

Macros

#define CLINKEDLIST_H
 

Typedefs

typedef struct _cListElem cListElem
 
typedef struct _cLinkedList cLinkedList
 

Functions

unsigned long cListLength (cLinkedList *myList)
 
int cListEmpty (cLinkedList *myList)
 
cListElemcListFirstElem (cLinkedList *myList)
 Returns the first element of a linked list.
 
cListElemcListLastElem (cLinkedList *myList)
 Returns the last element of a linked list.
 
cListElemcListNextElem (cLinkedList *myList, cListElem *myElem)
 Returns the next element of a linked list when provided an element from the list.
 
cListElemcListPrevElem (cLinkedList *myList, cListElem *myElem)
 Returns the previous element of a linked list, when provided an element from the list.
 
cListElemcListFindElem (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 *myData, cListElem *myElem)
 Insert a data point into a linked list after an existing element in the list.
 
int cListInsertBefore (cLinkedList *myList, void *myData, cListElem *myElem)
 Insert a data point into a linked list before an existing element in the list.
 
int cListAppend (cLinkedList *myList, void *myData)
 Append a data point into a linked list.
 
int cListPrepend (cLinkedList *myList, void *myData)
 Prepend a data point into a linked list.
 
void cListUnlinkElem (cLinkedList *myList, cListElem *myElem)
 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 *myList, void *myData)
 Unlinks a data point that is linked in a linked list.
 

Detailed Description

cLinkedList: A simple linked list manager for C/C++.

Author
Suraj Chakravarthi Raja

Definition in file cLinkedList.h.

Macro Definition Documentation

◆ CLINKEDLIST_H

#define CLINKEDLIST_H

Definition at line 10 of file cLinkedList.h.

Typedef Documentation

◆ cLinkedList

typedef struct _cLinkedList cLinkedList

Structure for a linked list of cListElem elements.

◆ cListElem

typedef struct _cListElem cListElem

Function Documentation

◆ cListAppend()

int cListAppend ( cLinkedList myList,
void *  newData 
)

Append a data point into a linked list.

Parameters
myListPointer to the cLinkedList linked list to which data needs to be linked.
myDataVoid pointer to the data point to be linked as an element into the linked list.
Returns
Returns 1 if successful and 0 otherwise.

Inserts the specified new data at the end of the supplied linked list as the last element.

Parameters
myListcLinkedList pointer to the linked list need to be used.
newDatavoid pointer to the new data to be inserted.
Returns
Upon successful insertion, the function returns a (int) 1.

Definition at line 370 of file cLinkedList.c.

◆ cListEmpty()

int cListEmpty ( cLinkedList myList)

Returns 1 if a linked list is empty.

Parameters
myListPointer to the cLinkedList linked list which needs to be checked.
Returns
Returns (int) 1 if the linked list is empty and 0 otherwise.

Checks to see if the cLinkedList linked list passed a parameter is empty.

Parameters
myListcLinkedList pointer of the linked list which we need to check if empty.
Returns
Returns 1 (TRUE) if the passed linked list is empty and 0 (FALSE) otherwise.

Definition at line 43 of file cLinkedList.c.

◆ cListFindData()

void * cListFindData ( cLinkedList myList,
void *  myData 
)

Find a data point in a linked list if it is present.

Parameters
myListPointer to the cLinkedList linked list being accessed.
myElemPointer to the data being searched for.
Returns
Void pointer to the data of the linked list if the data is found. NULL returned otherwise.

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.

Parameters
myListcLinkedList pointer to the linked list need to be read.
myDatavoid pointer to the data that would be held by the list element that needs to be found.
Returns
void pointer to the data found on the linked list. If myList is a null pointer, so will the output.

Definition at line 171 of file cLinkedList.c.

◆ cListFindElem()

cListElem * cListFindElem ( cLinkedList myList,
void *  myData 
)

Find an element in a linked list passed using the data linked in it.

Parameters
myListPointer to the cLinkedList linked list being accessed.
myElemPointer to the data which is linked to the element being search for.
Returns
Void pointer to element of the linked list if the data is linked in the list. NULL returned otherwise.

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.

Parameters
myListcLinkedList pointer to the linked list need to be read.
myDatavoid pointer to the data that would be held by the list element that needs to be found.
Returns
cListElem pointer to the first element found that holds the data being used to find the element. If myList is a null pointer, so will the output.

Definition at line 145 of file cLinkedList.c.

◆ cListFirstData()

void * cListFirstData ( cLinkedList myList)

Returns the first data point of a linked list.

Parameters
myListPointer to the cLinkedList linked list whose first data point is needed.
Returns
Void pointer to the first data point of the linked list. Returns NULL if empty.

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.

Parameters
myListcLinkedList pointer to the linked list need to be used.
Returns
void pointer to the data held by the first element in the linked list passed as a pointer. If myList is a null pointer, so will the output.

Definition at line 192 of file cLinkedList.c.

◆ cListFirstElem()

cListElem * cListFirstElem ( cLinkedList myList)

Returns the first element of a linked list.

Parameters
myListPointer to the cLinkedList linked list whose first element is needed.
Returns
Pointer (of type cListElem) to the first element of the linked list. Returns NULL if empty.

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.

Parameters
myListcLinkedList pointer to the linked list whose first element we need.
Returns
cListElem pointer to the first element of the linked list.

Definition at line 66 of file cLinkedList.c.

◆ cListInit()

int cListInit ( cLinkedList myList)

Initializes a doubly linked list.

Parameters
myListPointer to the cLinkedList linked list which has already been created.
Returns
Returns 1 if the successful, and 0 otherwise.

Dynamically initialized the cLinkedList pointer with a linked list.

Parameters
myListcLinkedList pointer to the linked list need to be used.
Returns
1 if the linked list was succesfully iniitialized and 0 if it wasn't.

Definition at line 282 of file cLinkedList.c.

◆ cListInsertAfter()

int cListInsertAfter ( cLinkedList myList,
void *  newData,
cListElem elem 
)

Insert a data point into a linked list after an existing element in the list.

Parameters
myListPointer to the cLinkedList linked list to which data needs to be linked.
myDataVoid pointer to the data point to be linked as an element into the linked list.
myElemPointer to the cListElem element in the linked list after which the new data point needs to be inserted.
Returns
Returns 1 if successul and 0 otherwise.

Inserts the data element passed into the linked list specified as a list element after the specified list element.

Parameters
myListcLinkedList pointer to the linked list need to be used.
newDatavoid pointer to the new data to be inserted.
elemcListElem pointer to the element next to which the new data needs to be inserted
Returns
Upon successful insertion, the function returns a (int) 1.

Definition at line 307 of file cLinkedList.c.

◆ cListInsertBefore()

int cListInsertBefore ( cLinkedList myList,
void *  newData,
cListElem elem 
)

Insert a data point into a linked list before an existing element in the list.

Parameters
myListPointer to the cLinkedList linked list to which data needs to be linked.
myDataVoid pointer to the data point to be linked as an element into the linked list.
myElemPointer to the cListElem element in the linked list before which the new data point needs to be inserted.
Returns
Returns 1 if successful and 0 otherwise.

Inserts the data element passed into the linked list specified as a list element before the specified list element.

Parameters
myListcLinkedList pointer to the linked list need to be used.
newDatavoid pointer to the new data to be inserted.
elemcListElem pointer to the element before which the new data needs to be inserted
Returns
Upon successful insertion, the function returns a (int) 1.

Definition at line 339 of file cLinkedList.c.

◆ cListLastData()

void * cListLastData ( cLinkedList myList)

Returns the last data point of a linked list.

Parameters
myListPointer to the cLinkedList linked list whose last data point is needed.
Returns
Void pointer to the last data point of the linked list. Returns NULL if empty.

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.

Parameters
myListcLinkedList pointer to the linked list need to be used.
Returns
void pointer to the data held by the last element in the linked list passed as a pointer. If myList is a null pointer, so will the output.

Definition at line 213 of file cLinkedList.c.

◆ cListLastElem()

cListElem * cListLastElem ( cLinkedList myList)

Returns the last element of a linked list.

Parameters
myListPointer to the cLinkedList linked list whose last element is needed.
Returns
Pointer (of type cListElem) to the last element of the linked list. Returns NULL if empty.

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.

Parameters
myListcLinkedList pointer to the linked list whose last element we need.
Returns
cListElem pointer to the last element of the linked list. If myList is a null pointer, so will the output.

Definition at line 83 of file cLinkedList.c.

◆ cListLength()

unsigned long cListLength ( cLinkedList myList)

Returns the length of a linked list.

Parameters
myListcLinkedList pointer of the linked list whose length is returned.
Returns
Length of the linked list passed as a parameter. Returns 0 if myList is a null pointer as well.

Returns the length of the cLinkedList linked list passed to it as a parameter.

Parameters
myListcLinkedList pointer of the linked list whose length is returned.
Returns
Length of the linked list passed as a parameter. Returns 0 if myList is a null pointer as well.

Definition at line 27 of file cLinkedList.c.

◆ cListNextData()

void * cListNextData ( cLinkedList myList,
void *  myData 
)

Returns the next data point of a linked list when provided a data point from the list.

Parameters
myListPointer to the cLinkedList linked list being accessed.
myElemPointer to the data point in the list whose next data point is needed.
Returns
Void pointer to the next data point of the linked list if both data points exist. Returns NULL otherwise.

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.

Parameters
myListcLinkedList pointer to the linked list need to be used.
myDatavoid pointer to the data next to which we get the want look for the next data.
Returns
void pointer to the data held by the next element in the linked list passed as a pointer. If myList is a null pointer, so will the output.

Definition at line 236 of file cLinkedList.c.

◆ cListNextElem()

cListElem * cListNextElem ( cLinkedList myList,
cListElem myElem 
)

Returns the next element of a linked list when provided an element from the list.

Parameters
myListPointer to the cLinkedList linked list being accessed.
myElemPointer to the cListElem element in the list whose next element is needed.
Returns
Pointer (of type cListElem) to the next element of the linked list if it exists. Returns NULL otherwise.

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.

Parameters
myListcLinkedList pointer to the linked list need to be read.
myElemThe function returns the element next to the element pointed to by this cListElem pointer.
Returns
cListElem pointer to the element next to the element passed as a parameter. If myList or myElem is a null pointer, so will the output.

Definition at line 101 of file cLinkedList.c.

◆ cListPrepend()

int cListPrepend ( cLinkedList myList,
void *  newData 
)

Prepend a data point into a linked list.

Parameters
myListPointer to the cLinkedList linked list to which data needs to be linked.
myDataVoid pointer to the data point to be linked as an element into the linked list.
Returns
Returns 1 if successful and 0 otherwise.

Inserts the specified new data at the beginning of the supplied linked list as the first element.

Parameters
myListcLinkedList pointer to the linked list need to be used.
newDatavoid pointer to the new data to be inserted.
Returns
Upon successful insertion, the function returns a (int) 1.

Definition at line 383 of file cLinkedList.c.

◆ cListPrevData()

void * cListPrevData ( cLinkedList myList,
void *  myData 
)

Returns the previous data point of a linked list, when provided a data point from the list.

Parameters
myListPointer to the cLinkedList linked list being accessed.
myElemPointer to the data point in the list whose previous data point is needed.
Returns
Void pointer to the previous data point the linked list if both data points exist. Returns NULL otherwise.

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.

Parameters
myListcLinkedList pointer to the linked list need to be used.
myDatavoid pointer to the data before which we look for the previous data.
Returns
void pointer to the data held by the previous element in the linked list passed as a pointer. If myList or is a null pointer, so will the output.

Definition at line 258 of file cLinkedList.c.

◆ cListPrevElem()

cListElem * cListPrevElem ( cLinkedList myList,
cListElem myElem 
)

Returns the previous element of a linked list, when provided an element from the list.

Parameters
myListPointer to the cLinkedList linked list being accessed.
myElemPointer to the cListElem element in the list whose previous element is needed.
Returns
Pointer (of type cListElem) to the previous element of the linked list if it exists. Returns NULL otherwise.

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.

Parameters
myListcLinkedList pointer to the linked list need to be read.
myElemThe function returns the element beefore the element pointed to by this cListElem pointer.
Returns
cListElem pointer to the element that is before the element passed as a parameter. If myList or myElem is a null pointer, so will the output.

Definition at line 122 of file cLinkedList.c.

◆ cListUnlinkAll()

void cListUnlinkAll ( cLinkedList myList)

Unlinks all the elements from a linked list. This does not remove the actual data points linked.

Parameters
myListPointer 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.

Parameters
myListcLinkedList pointer to the linked list need to be used.

Definition at line 424 of file cLinkedList.c.

◆ cListUnlinkData()

void cListUnlinkData ( cLinkedList delList,
void *  delData 
)

Unlinks a data point that is linked in a linked list.

Parameters
myListPointer to the cLinkedList linked list from which a data point needs to be unlinked.
myDataVoid 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.

Parameters
delListcLinkedList pointer to the linked list need to be used.
delDatavoid pointer to the data whose element needs to be unlinked from the list.

Definition at line 443 of file cLinkedList.c.

◆ cListUnlinkElem()

void cListUnlinkElem ( cLinkedList myList,
cListElem delElem 
)

Unlinks an element from a linked list. This does not remove the actual data point linked.

Parameters
myListPointer to the cLinkedList linked list from which an element needs to be unlinked.
myElemPointer 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.

Parameters
myListcLinkedList pointer to the linked list need to be used.
delElemcListElem pointer to the element that needs to unlinked.

Definition at line 397 of file cLinkedList.c.