Changed linkedlist IO relative to a node

This commit is contained in:
Leonardo committed 2019-05-07 17:20:01 -03:00
1 parent 2f767f7623
commit 21ab3eeb07
2 files changed
+98 -80

No files matched your search

+22 -6
View File
@@ -7,13 +7,14 @@
* Leonardo Vencovsky (https://github.com/LeoVen)
*
*/
#include "linkedlist.h"
#include <stdio.h>
#include <assert.h>
#include "linkedlist.h"
#include <inttypes.h>
LINKEDLIST_GENERATE(l, list, /* static */, int)
int main(int argc, char const *argv[])
int main(void)
{
list *l = l_new();
@@ -25,14 +26,14 @@ int main(int argc, char const *argv[])
{
if (node->data % 3 == 0)
{
l_insert_prv(node, 33);
l_insert_nxt(node, 99);
l_insert_before(l, node, 33);
l_insert_after(l, node, 99);
node = node->next; // skip 99
}
}
size_t s = 0;
for (list_node *node = l_front_node(l); node != NULL; node = l_next_node(node), s++)
for (list_node *node = l_head(l); node != NULL; node = l_next_node(node), s++)
{
if (node->prev == NULL)
printf("[ %d, ", node->data);
@@ -42,7 +43,22 @@ int main(int argc, char const *argv[])
printf("%d, ", node->data);
}
printf("List Head: %d\nList Tail: %d\nList Count: %d\n", l->head->data, l->tail->data, l->count);
printf("\n\n");
s = 0;
for (list_node *node = l_tail(l); node != NULL; node = l_prev_node(node), s++)
{
if (node->next == NULL)
printf("[ %d, ", node->data);
else if (node->prev == NULL)
printf("%d ]\n", node->data);
else
printf("%d, ", node->data);
}
printf("\n\n");
printf("List Head: %d\nList Tail: %d\nList Count: %" PRIuMAX "\n", l->head->data, l->tail->data, l->count);
assert(s == l->count);