aboutsummaryrefslogtreecommitdiff
path: root/src/lib/list.h
blob: 58a7751567052a9a581a448570374b3e123c2e99 (plain)
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
#ifndef LIST_H
#define LIST_H

#include <stdio.h>
#include <stdlib.h>

// Node
typedef struct Node {
  int value;
  struct Node* next;
} Node;

// Create & initialise a new node
Node* node_init(int value);

// Print linked list values
void list_print(Node* head);
void list_vprint(Node* head);

// Return number of nodes in list
// O(n)
int list_length(Node* head);

// Prepend a value to the list
// O(1)
void list_push(Node** head, int value);

// Pop (remove) first node
// O(1)
int list_pop(Node** head);

// Append value to the end of the list
// O(n)
void list_append(Node* head, int value);

// Insert a value to the list at index
// O(n)
void list_insert(Node** head, int value, int index);

// Free nodes from memory
// O(n)
void list_free(Node** head);

// Remove last node
// O(n)
int list_rmlast(Node** head);

// Remove node at index
// O(n)
int list_rm(Node** head, int index);

#endif //LIST_H