diff options
| author | Blake Romero <blake@blkrom.com> | 2024-09-19 18:02:00 +0100 |
|---|---|---|
| committer | Blake Romero <blake@blkrom.com> | 2024-10-30 10:13:26 +0000 |
| commit | b018310aa02d235a7f3fe3c3baf9dd70b459fe38 (patch) | |
| tree | 75d8b43f9d06d2ea57e4338940c7e6e7b13a3ca6 | |
| parent | 0ea8c07ed48b9ce4cf9ee74a559ba6378d467866 (diff) | |
Refactor lllength & llprint functions
| -rw-r--r-- | src/ll.c | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -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) { |
