aboutsummaryrefslogtreecommitdiff
path: root/src/ll.h
diff options
context:
space:
mode:
authorBlake Romero <blake@blkrom.com>2024-09-18 00:32:53 +0100
committerBlake Romero <blake@blkrom.com>2024-10-30 10:13:26 +0000
commit45c1fbf4dfe5c7a7243b625eb8a600bdce6c748f (patch)
tree0c19f2d45941d2027ae5f07586af4bd427a5cdf6 /src/ll.h
parentd1841d4d2a087d1681d1fb483301b4a7e4722f98 (diff)
Add makefile & tests
Diffstat (limited to 'src/ll.h')
-rw-r--r--src/ll.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ll.h b/src/ll.h
new file mode 100644
index 0000000..f777ace
--- /dev/null
+++ b/src/ll.h
@@ -0,0 +1,54 @@
+#ifndef LL
+#define LL
+
+#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