Add support for tree structures. Search function with DFS, BFS currently unimplemented. Improve linked list handling; fix bug in circular list detection.
This commit is contained in:
33
tests/test_linkedlist.c
Normal file
33
tests/test_linkedlist.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <akstdlib.h>
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *myiter(aksl_ListNode *node, void *data)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
int count;
|
||||
FAIL_ZERO_RETURN(e, node, AKERR_NULLPOINTER, "node");
|
||||
FAIL_ZERO_RETURN(e, node->data, AKERR_NULLPOINTER, "node->data");
|
||||
// This function doesn't use *data so we don't check it
|
||||
|
||||
PASS(e, aksl_fprintf(&count, stderr, "Visiting node : %s", node->data));
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
aksl_ListNode mylist;
|
||||
char *node1str = "Node 1";
|
||||
aksl_ListNode node1;
|
||||
char *node2str = "Node 2";
|
||||
aksl_ListNode node2;
|
||||
|
||||
node1->data = (void *)&node1str;
|
||||
PASS(e, aksl_list_push(&mylist, &node1));
|
||||
|
||||
node2->data = (void *)&node2str;
|
||||
PASS(e, aksl_list_push(&mylist, &node2));
|
||||
|
||||
PASS(e, aksl_list_iterate(&mylist, &myiter, NULL));
|
||||
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
Reference in New Issue
Block a user