#include #include #include "tree.h" /* If we're on FreeBSD, you can use this instead: #include */ struct tree_node { int data; RB_ENTRY(tree_node) tree_entry; }; int tncompare(struct tree_node *a, struct tree_node *b){ return a->data - b->data; } RB_HEAD(int_tree, tree_node); RB_GENERATE_STATIC(int_tree, tree_node, tree_entry, tncompare); struct int_tree it; char contains(int n){ return 0 != RB_FIND(int_tree, &it, (struct tree_node*)&n); } void insert_new(int n){ struct tree_node *nn = malloc(sizeof(struct tree_node)); nn->data = n; RB_INSERT(int_tree, &it, nn); } int main(){ insert_new(5); insert_new(600); printf("Tree minimum: %d\n", RB_MIN(int_tree, &it)->data); puts("Printing Tree:"); struct tree_node *i; RB_FOREACH(i, int_tree, &it){ printf("%d ", i->data); } puts(""); if(contains(5)) puts("The tree contains 5"); else puts("The tree does not contain 5"); if(contains(17)) puts("The tree contains 17"); else puts("The tree does not contain 17"); return 0; }