about summary refs log tree commit diff
path: root/src/search/tdestroy.c
blob: 6f430bda182c948950b24a3886932df7f1321cb1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define _GNU_SOURCE
#include <stdlib.h>
#include <search.h>

struct node {
	void *key;
	struct node *left;
	struct node *right;
};

void tdestroy(void *root, void (*freekey)(void *))
{
	struct node *r = root;

	if (r == 0)
		return;
	tdestroy(r->left, freekey);
	tdestroy(r->right, freekey);
	freekey(r->key);
	free(r);
}