aboutsummaryrefslogtreecommitdiff
path: root/src/lib/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/list.h')
-rw-r--r--src/lib/list.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/list.h b/src/lib/list.h
new file mode 100644
index 0000000..58a7751
--- /dev/null
+++ b/src/lib/list.h
@@ -0,0 +1,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