Added linkedlist node functions
This commit is contained in:
1 parent
9438cd066d
commit
5177ad9a8d
2 files changed
+160
-7
No files matched your search
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "../src/linkedlist.h"
|
||||
|
||||
LINKEDLIST_GENERATE(l, list, , , int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
list *l = l_new();
|
||||
|
||||
for (int i = 0; i < 97; i++)
|
||||
l_push_back(l, i);
|
||||
|
||||
// Add 99 after and 33 before every node where its data is divisible by 3
|
||||
for (list_node *node = l->head; node != NULL; node = node->next)
|
||||
{
|
||||
if (node->data % 3 == 0)
|
||||
{
|
||||
l_insert_prv(node, 33);
|
||||
l_insert_nxt(node, 99);
|
||||
node = node->next; // skip 99
|
||||
}
|
||||
}
|
||||
|
||||
size_t s = 0;
|
||||
for (list_node *node = l->head; node != NULL; node = node->next, s++)
|
||||
{
|
||||
if (node->prev == NULL)
|
||||
printf("[ %d, ", node->data);
|
||||
else if (node->next == NULL)
|
||||
printf("%d ]\n", node->data);
|
||||
else
|
||||
printf("%d, ", node->data);
|
||||
}
|
||||
|
||||
printf("List Head: %d\nList Tail: %d\nList Count: %d\n", l->head->data, l->tail->data, l->count);
|
||||
|
||||
assert(s == l->count);
|
||||
|
||||
l_free(l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user