A3_DobleSpiel/bintree.h
DESKTOP-0TGNH6T\alial ccd912be91 bintree and tests
2026-06-08 16:45:03 +02:00

30 lines
983 B
C

#ifndef BINTREE_H
#define BINTREE_H
#include <stdlib.h>
typedef int (*CompareFctType)(const void *arg1, const void *arg2);
typedef struct node
{
void *data;
struct node *left;
struct node *right;
} TreeNode;
// Adds a copy of data's pointer destination to the tree using compareFct for ordering.
// Accepts duplicates if isDuplicate is NULL. Otherwise duplicates are ignored and
// isDuplicate is set to 1. If a new entry is added, isDuplicate is set to 0.
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate);
// Iterates over the tree in sorted order. If root is not NULL, a new iteration starts.
// If root is NULL, the next entry of the last tree is returned.
void *nextTreeData(TreeNode *root);
// Releases all memory resources, including data copies.
void clearTree(TreeNode *root);
// Returns the number of entries in the tree given by root.
unsigned int treeSize(const TreeNode *root);
#endif