From 44a4374fd1e0335907d782237ca9cbf16367e44f Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Thu, 21 Dec 2023 19:25:34 +0100 Subject: [PATCH] remove llist --- engine/llist.c | 99 -------------------------------------------------- engine/llist.h | 21 ----------- 2 files changed, 120 deletions(-) delete mode 100644 engine/llist.c delete mode 100644 engine/llist.h diff --git a/engine/llist.c b/engine/llist.c deleted file mode 100644 index c8472f3..0000000 --- a/engine/llist.c +++ /dev/null @@ -1,99 +0,0 @@ -/* llist.c - * Generic Linked List implementation - */ - -#include -#include -#include "llist.h" - -llist *llist_create(TodoItem *new_item) -{ - TodoItemNode *new_node; - - llist *new_list = (llist *)malloc(sizeof (llist)); - *new_list = (TodoItemNode *)malloc(sizeof (TodoItemNode)); - - new_node = *new_list; - new_node->item = new_item; - new_node->next = NULL; - return new_list; -} - -void llist_free(llist *list) -{ - TodoItemNode *curr = *list; - TodoItemNode *next; - - while (curr != NULL) { - next = curr->next; - free(curr); - curr = next; - } - - free(list); -} - -void llist_push(llist *list, TodoItem *item) -{ - TodoItemNode *head; - TodoItemNode *new_node; - if (list == NULL || *list == NULL) { - fprintf(stderr, "llist_add_inorder: list is null\n"); - } - - head = *list; - - // Head is empty node - if (head->item == NULL) - head->item = item; - - // Head is not empty, add new node to front - else { - new_node = malloc(sizeof (TodoItemNode)); - new_node->item = item; - new_node->next = head; - *list = new_node; - } -} - -TodoItem *llist_pop(llist *list) -{ - TodoItem *popped_item; - TodoItemNode *head = *list; - - if (list == NULL || head->item == NULL) - return NULL; - - popped_item = head->item; - *list = head->next; - - free(head); - - return popped_item; -} - -void llist_print(llist *list, void (*print)(TodoItem *)) -{ - TodoItemNode *curr = *list; - while (curr != NULL) { - print(curr->item); - printf(" "); - curr = curr->next; - } - putchar('\n'); -} - -unsigned int llist_length(llist *list) { - if (list == NULL) { - return 0; - } - - TodoItemNode *curr = *list; - unsigned int length = 0; - while (curr != NULL) { - length++; - curr = curr->next; - } - - return length; -} diff --git a/engine/llist.h b/engine/llist.h deleted file mode 100644 index 3c1dd99..0000000 --- a/engine/llist.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef LLIST_H -#define LLIST_H -#include "todo.h" -/* llist.h - * Generic Linked List - */ - -typedef struct Node { - TodoItem *item; - struct Node *next; -} TodoItemNode; - -typedef TodoItemNode *llist; - -llist *llist_create(TodoItem *item); -void llist_free(llist *list); -void llist_push(llist *list, TodoItem *item); -TodoItem *llist_pop(llist *list); -void llist_print(llist *list, void (*print)(TodoItem *item)); -unsigned int llist_length(llist *list); -#endif