TDELETE - delete node in binary tree.
(Compatible with UNIX System V C)
Usage:
#include <search.h>
char *tdelete();
ptr = tdelete( key, rootptr, compar);
Where:
- char *key;
- points to the key of the node you want to delete. This
can actually be any type of information, but the pointer
must be cast into (char *).
- char **rootptr;
- points to a variable that points to the root of the tree.
If "*rootptr" is NULL, the tree is empty. If
"rootptr" itself is NULL, "tdelete"
will return the NULL pointer.
- int (*compar)(char *,char *);
- is a pointer to a user-defined function that determines
whether or not two keys are equal. This function should
take two (char *) arguments; one will point to the key
you want to find and the other will point to a key in the
tree. The function should return a negative integer if
the first argument is less than the second; it should
return a positive integer if the first argument is
greater than the second; and it should return zero if the
two arguments are equal.
- char *ptr;
- points to the parent of the node that was deleted. If the
specified key was not found in the tree, the NULL pointer
is returned. If the node that was deleted was the root of
the tree, "ptr" will point to the new root.
Description:
"tdelete" deletes a node from a binary tree. It uses
your "compar" function to compare elements in the tree.
The "compar" you use does not have to do a
byte-by-byte comparison between the key and the tree node
information. For example, the nodes may be an array of C
structures and "compar" may only look at a particular
field when comparing two structures. In this case, the original
search key might just be a dummy, with only the significant field
filled in.
See Also:
expl c lib tfind
expl c lib tsearch
expl c lib twalk
Copyright © 1996, Thinkage Ltd.