-
Notifications
You must be signed in to change notification settings - Fork 0
/
IteratedList.h
52 lines (40 loc) · 1.36 KB
/
IteratedList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* IteratedList.h
* Header file for singly linked iterated list implementation.
*
* @author jonl
*
*/
#include "Bool.h"
#ifndef LIST_H_
#define LIST_H_
typedef struct listnode ListNodeStruct, *ListNode_PNTR;
struct listnode {
void *payload;
ListNode_PNTR tail;
};
typedef struct list ListStruct, *List_PNTR;
struct list {
void (*decRef)(List_PNTR pntr);
ListNode_PNTR first; // the first node in the list, NULL if list is empty
ListNode_PNTR next; // used for iterating over lists using getNextElement
};
// constructor
extern List_PNTR Construct_List();
// functions to insert into, get and remove elements from a list
extern void insertElement(List_PNTR l, void *element);
extern void *getNextElement(List_PNTR l);
extern void *getElementN(List_PNTR l, unsigned index);
extern void *getRandomElement(List_PNTR l);
extern unsigned getListLength(List_PNTR l);
extern bool containsElement(List_PNTR l, void *element);
extern bool isEmpty(List_PNTR l);
extern void *searchList(List_PNTR l, int (*f)(void *element, void *key), void *key);
extern void removeElement(List_PNTR l, void *element);
extern void removeAllElements(List_PNTR l);
extern void listFreeNode(ListNode_PNTR node);
// Last function only used for testing, can be commented out to save space
#ifdef DALDEBUG
extern void displayList(List_PNTR l, void (*f)(void *element));
#endif
#endif