From b018310aa02d235a7f3fe3c3baf9dd70b459fe38 Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Thu, 19 Sep 2024 18:02:00 +0100 Subject: Refactor lllength & llprint functions --- src/ll.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ll.c b/src/ll.c index 7059ec5..fdf86af 100644 --- a/src/ll.c +++ b/src/ll.c @@ -13,32 +13,29 @@ Node* llnode(int value) { void llprint(Node* head) { Node* node = head; printf("[ "); - do { + while (node != NULL) { printf("%i ", node->value); node = node->next; - } while (node != NULL); + } printf("]\n"); free(node); } void llvprint(Node* head) { Node* node = head; - do { + while (node != NULL) { printf("[*] %i\n", node->value); node = node->next; printf(" |\n"); - } while (node != NULL); + } printf("[/] %s\n", (char*) node); } int lllength(Node* head) { - Node* node = head; - int count = 0; - while (node != NULL) { - ++count; - node = node->next; - } - return count; + Node* n = head; + int i = 0; + for (; n != NULL; ++i) n = n->next; + return i; } void llpush(Node** head, int value) { -- cgit