forked from brown-cs0330/lab06-alloc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.h
More file actions
59 lines (46 loc) · 1.81 KB
/
linkedlist.h
File metadata and controls
59 lines (46 loc) · 1.81 KB
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
53
54
55
56
57
58
59
#ifndef linkedlist_H
#define linkedlist_H
// Declare an opaque struct (defined in linkedlist.c)
typedef struct LinkedList LinkedList;
/******************************
* Creation/deletion functions
******************************/
/* Create a new linkedlist with the given element functions and return it */
LinkedList *linkedlist_new(int (*equals)(void *, void *), void *(*copy)(void *),
void (*delete)(void *));
/* Delete the given linked list */
void linkedlist_delete(LinkedList *linkedlist);
/******************************
* Access/modification functions
******************************/
/* Add a copy of the given element to the tail of the list */
void linkedlist_append(LinkedList *linkedlist, void *element);
/*
* Insert a copy of the given element at the given index (before the element
* that currently has that index).
* Inserting at size is equivalent to appending.
* Return 1 if the element was added successfully
* 0 otherwise (if the index is invalid)
*/
int linkedlist_insert(LinkedList *linkedlist, void *element, int index);
/* Return 1 if the given element is in the list
* 0 otherwise
*/
int linkedlist_contains(LinkedList *linkedlist, void *element);
/* Remove the first ocurrence of the given element from the list
* Return 1 if the element was removed successfully
* 0 otherwise (if the element was not found)
*/
int linkedlist_remove(LinkedList *linkedlist, void *element);
/******************************
* Other utility functions
******************************/
/* Get the size of the given list */
int linkedlist_size(LinkedList *linkedlist);
/* Print a representation of the linked list,
* using the given function to print each
* element
*/
void linkedlist_print(LinkedList *linkedlist, FILE *stream,
void (*print_element)(FILE *, void *));
#endif