cLinkedList
A simple C library for doubly linked list creation and management
Loading...
Searching...
No Matches
cLinkedList.h
Go to the documentation of this file.
1
7#pragma once
8
9#ifndef CLINKEDLIST_H
10#define CLINKEDLIST_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include <stddef.h>
17#include "macrodef.h"
18
22typedef struct _cListElem {
24 void *obj;
30
34typedef struct _cLinkedList {
36 unsigned long num_elem;
40
41// Linked list status functions
42
49unsigned long cListLength (cLinkedList *myList);
50
56int cListEmpty (cLinkedList *myList);
57
58// Linked list read functions
59
66
73
80cListElem * cListNextElem (cLinkedList *myList, cListElem *myElem);
81
88cListElem * cListPrevElem (cLinkedList *myList, cListElem *myElem);
89
96cListElem * cListFindElem (cLinkedList *myList, void *myData);
97
104void * cListFindData (cLinkedList *myList, void *myData);
105
111void * cListFirstData (cLinkedList *myList);
112
118void * cListLastData (cLinkedList *myList);
119
126void * cListNextData (cLinkedList *myList, void *myData);
127
134void * cListPrevData (cLinkedList *myList, void *myData);
135
136// Linked list creation functions
137
143int cListInit (cLinkedList *myList);
144
152int cListInsertAfter (cLinkedList *myList, void *myData, cListElem *myElem);
153
161int cListInsertBefore (cLinkedList *myList, void *myData, cListElem *myElem);
162
169int cListAppend (cLinkedList *myList, void *myData);
170
177int cListPrepend (cLinkedList *myList, void *myData);
178
179// Linked list unlink functions
180
186void cListUnlinkElem (cLinkedList *myList, cListElem *myElem);
187
192void cListUnlinkAll (cLinkedList *myList);
193
199void cListUnlinkData (cLinkedList *myList, void *myData);
200
201#ifdef __cplusplus
202}
203#endif
204
205#endif //CLINKEDLIST_H
int cListInsertAfter(cLinkedList *myList, void *myData, cListElem *myElem)
Insert a data point into a linked list after an existing element in the list.
Definition: cLinkedList.c:307
cListElem * cListNextElem(cLinkedList *myList, cListElem *myElem)
Returns the next element of a linked list when provided an element from the list.
Definition: cLinkedList.c:101
void * cListLastData(cLinkedList *myList)
Returns the last data point of a linked list.
Definition: cLinkedList.c:213
void * cListFirstData(cLinkedList *myList)
Returns the first data point of a linked list.
Definition: cLinkedList.c:192
int cListEmpty(cLinkedList *myList)
Definition: cLinkedList.c:43
cListElem * cListFindElem(cLinkedList *myList, void *myData)
Find an element in a linked list passed using the data linked in it.
Definition: cLinkedList.c:145
void * cListFindData(cLinkedList *myList, void *myData)
Find a data point in a linked list if it is present.
Definition: cLinkedList.c:171
struct _cLinkedList cLinkedList
cListElem * cListFirstElem(cLinkedList *myList)
Returns the first element of a linked list.
Definition: cLinkedList.c:66
void * cListPrevData(cLinkedList *myList, void *myData)
Returns the previous data point of a linked list, when provided a data point from the list.
Definition: cLinkedList.c:258
cListElem * cListPrevElem(cLinkedList *myList, cListElem *myElem)
Returns the previous element of a linked list, when provided an element from the list.
Definition: cLinkedList.c:122
unsigned long cListLength(cLinkedList *myList)
Definition: cLinkedList.c:27
int cListInsertBefore(cLinkedList *myList, void *myData, cListElem *myElem)
Insert a data point into a linked list before an existing element in the list.
Definition: cLinkedList.c:339
int cListAppend(cLinkedList *myList, void *myData)
Append a data point into a linked list.
Definition: cLinkedList.c:370
void * cListNextData(cLinkedList *myList, void *myData)
Returns the next data point of a linked list when provided a data point from the list.
Definition: cLinkedList.c:236
int cListPrepend(cLinkedList *myList, void *myData)
Prepend a data point into a linked list.
Definition: cLinkedList.c:383
struct _cListElem cListElem
cListElem * cListLastElem(cLinkedList *myList)
Returns the last element of a linked list.
Definition: cLinkedList.c:83
void cListUnlinkData(cLinkedList *myList, void *myData)
Unlinks a data point that is linked in a linked list.
Definition: cLinkedList.c:443
void cListUnlinkAll(cLinkedList *myList)
Unlinks all the elements from a linked list. This does not remove the actual data points linked.
Definition: cLinkedList.c:424
int cListInit(cLinkedList *myList)
Initializes a doubly linked list.
Definition: cLinkedList.c:282
void cListUnlinkElem(cLinkedList *myList, cListElem *myElem)
Unlinks an element from a linked list. This does not remove the actual data point linked.
Definition: cLinkedList.c:397
cListElem anchor
Definition: cLinkedList.h:38
unsigned long num_elem
Definition: cLinkedList.h:36
struct _cListElem * prevElem
Definition: cLinkedList.h:28
struct _cListElem * nextElem
Definition: cLinkedList.h:26
void * obj
Definition: cLinkedList.h:24