From 6469b2c887716a5c6a0e191c5ffeb7972f7f7b34 Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Mon, 2 Sep 2024 01:20:18 +0100 Subject: Add initial linked list implementation --- linkedlist/ll.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 linkedlist/ll.h (limited to 'linkedlist/ll.h') diff --git a/linkedlist/ll.h b/linkedlist/ll.h new file mode 100644 index 0000000..0e15c43 --- /dev/null +++ b/linkedlist/ll.h @@ -0,0 +1,54 @@ +#ifndef LL +#define LL + +#define NEW_NODE llnode(); + +#include +#include + +// Node +typedef struct Node { + int value; + struct Node* next; +} Node; + +// Create & initialise a new node +Node* llnode(); + +// Print linked list values +// O() +void llprint(Node* head); +void llvprint(Node* head); + +// Return number of nodes in list +// O(n) +int llcount(Node* head); + +// Append value to the end of the list +// O(n) +void llappend(Node* head, int value); + +// Prepend a value to the list +// O(1) +void llpush(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 +void llfree(Node* head); + +// Pop (remove) first node +// O(1) +int llpop(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 -- cgit