#ifndef TREE_H #define TREE_H #include /** \file tree.h tree.c * most basic tree-implemenation: this is meant as base for all classes * and kept as simple as possible in order to prevent overheads. * relying classes should therefor be performant and easy to maintain. */ /** \example ./tst/test.c * This example generates a new tree and adds elements. * and prints them on stdout. */ /// basic structure of a tree- every node can have a child and is part of a /// linked list, so it has a next-element typedef struct Tree { const void* data; struct Tree* next; struct Tree* child; } Tree; /// creates a new Tree-structure with a dataentry... extern Tree* tree_new(const void* const data); /// appends the tree to the bottom (adds element to the list) extern Tree* tree_add(Tree* tree, const void* const data); /// appends the tree to the bottom (adds element to the list) extern Tree* tree_addChildTop(Tree* tree, const void* const data); /// appends the tree to the bottom (adds element to the list) extern Tree* tree_addtop(Tree* tree, const void* const data); /// adds a childnode. same as adding an element to the list of its child extern Tree* tree_addChild(Tree* tree, const void* const data); /// frees all nodes (data* has to be freed seperatly) extern void tree_free(Tree* tree, void((*free_function)(const void*))); /// adds another tree at the end of the tree-structure (last element addition) extern Tree* tree_join(Tree* tree, Tree* subtree); /// extends another tree as child of the given extern Tree* tree_extend(Tree* tree, Tree* subtree); /// iterates over all tree-elements, until return-value of fn is NULL /// - uses the return void* from fn() as next function, so that you /// keep the order in deep structures. extern void tree_iterate(Tree* tree, void* (*fn)(const void* data)); #endif