diff --git a/0x17-doubly_linked_lists/0-print_dlistint.c b/0x17-doubly_linked_lists/0-print_dlistint.c index 8be978e..b50f055 100644 --- a/0x17-doubly_linked_lists/0-print_dlistint.c +++ b/0x17-doubly_linked_lists/0-print_dlistint.c @@ -1,26 +1,29 @@ #include "lists.h" + /** - * print_dlistint - prints all elements of linked list - * @h: pointer to the list - * Return: the number of nodes + * print_dlistint - prints all the elements of a dlistint_t list. + * @h: pointer to the head of the list + * + * Return: number of nodes */ + size_t print_dlistint(const dlistint_t *h) { - dlistint_t *newnode; - size_t count = 0; + + int counter = 0; if (h == NULL) - return (count); - newnode = malloc(sizeof(dlistint_t)); - newnode->n = h->n; - newnode->prev = h->prev; - newnode->next = h->next; + return (counter); - while (newnode != NULL) + while (h->prev != NULL) + h = h->prev; + + while (h != NULL) { - printf("%d\n", newnode->n); - count++; - newnode = newnode->next; + printf("%d\n", h->n); + h = h->next; + counter++; } - return (count); + + return (counter); } diff --git a/0x17-doubly_linked_lists/e b/0x17-doubly_linked_lists/e new file mode 100755 index 0000000..e107231 Binary files /dev/null and b/0x17-doubly_linked_lists/e differ