-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list.h
41 lines (34 loc) · 1.53 KB
/
linked_list.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
// This program is written to demonstrate the basic construction of a
// doubly-linked list data structure.
#include <stdbool.h>
#include <stdlib.h>
/* - TYPEDEFS - */
// This line allows you to specify what kind of data you want the linked list
// to contain. THIS CODE IS ONLY DESIGNED FOR NUMERIC TYPES - int, char, float,
// double, etc.
typedef int DATA_TYPE;
// Nodes are a container for the list data that includes pointers to the next
// and previous nodes in the list.
typedef struct node Node;
// List is an accessor for the nodes in the list. It contains a pointer for the
// first node in the list, the last node in the list, and a size_t that holds
// the size of the list.
typedef struct list List;
/* - LIST FUNCTIONS - */
// Generate a pointer to the list accessor
List *make_list();
// Append a new item to the end of the list
bool list_add(List *list, DATA_TYPE value);
// Insert a new item at a particular location in the list. Index starts at 0
bool list_insert(List *list, DATA_TYPE value, size_t index);
// Remove an item from the list at a particular index location
bool list_remove(List *list, size_t index);
// Return the size of the list. Returns -1 if list doesn't exist.
int list_size(List *list);
// Retrieve the data from the particular index location of the list
DATA_TYPE list_get_value(List *list, size_t index);
// Free all allocated memory in the list. The List * needs to be set to NULL
bool destroy_list(List *list);
/* - SORT FUNCTIONS - */
// Perform a bubble sort algorithm on the list
bool list_bubble_sort(List * list);