-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist.h
78 lines (66 loc) · 1.52 KB
/
linkedlist.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef PROJB_24473_LINKEDLIST_H
#define PROJB_24473_LINKEDLIST_H
#include <stdio.h>
#include <stdlib.h>
#include "constants.h"
// Generic linked list
typedef struct node {
void *data;
struct node *next;
}NODE;
/*
* Adds an element to the end of the linked list
* - return 0: Success
* - return -3: Out of memory
*/
int push(NODE **start, void *data, size_t size);
/*
* Removes the last element of the linked list
* - return 0: Success
* - return -2: Empty list
*/
int pop(NODE **start);
/*
* Adds an element to the start of the linked list
* - return 0: Success
* - return -3: Out of memory
*/
int unshift(NODE **start, void *data, size_t size);
/*
* Removes the first element of the linked list
* - return 0: Success
* - return -2: List is empty
*/
int shift(NODE **start);
/*
* Removes an element given an index
* - return 0: Success
* - return -1: Element not found
* - return -2: List is empty
*/
int splice(NODE **start, int index);
/*
* Returns the size of the linked list
*/
int length(NODE *start);
/*
* Deletes all elements of the linked list
*/
void clear(NODE **start);
/*
* Checks if the linked list is empty
* - return 1: is empty
* - return 0: not empty
*/
int isEmpty(NODE **start);
/*
* Returns the last element of the linked list or NULL
*/
NODE* last_node(NODE *start);
/*
* Appends data to file given the filename
* - return 0: Success
* - return -3: Error opening file
*/
int appendToFile(char filename[MAX], void* data, size_t size);
#endif //PROJB_24473_LINKEDLIST_H