aboutsummaryrefslogtreecommitdiff
path: root/src/ll.h
blob: 9286dfd362b1f4e0081eef5da318d90bfd646a86 (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
53
54
#ifndef LL_H
#define LL_H

#define NEW_NODE llnode();

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

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

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

// Print linked list values
void llprint(Node* head);
void llvprint(Node* head);

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

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

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

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

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

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

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

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

#endif //LL_H