home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OBJASM.ZIP
/
OUFIND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-15
|
2KB
|
51 lines
#include <stdio.h>
#include "o.h"
char *find( data, root_node, cmp_routine, node_ptr )
char *data; /* pointer to data to find */
NODE_T *root_node; /* pointer to root node */
int (*cmp_routine)( void *, void * ); /* routine used to compare */
/* values at two nodes */
NODE_T **node_ptr; /* Ptr to node found */
{
NODE_T *curr_node;
NODE_T *child_node;
int curr_direct;
/* Prepare initial value for tree traversal */
child_node = root_node;
/*
** Traverse tree looking for the place to insert this new node. If
** we find a node which gives a comparison result of 0 (equal), then
** we cannot insert this new node. To indicate this duplicate value,
** a non-zero value is returned (the value happens to be a pointer to
** node which contains the duplicate value).
*/
do {
curr_node = child_node;
/* Compare this new node with the node at this position in the
** tree and determine which direction to proceed from here.
*/
curr_direct = (* cmp_routine)( curr_node->data, data );
/* is this node is a duplicate node?
*/
if ( node_ptr && curr_direct == RIGHT ) {
*node_ptr = curr_node;
}
if ( curr_direct == EQUAL ) {
if ( node_ptr ) {
*node_ptr = curr_node;
}
return ( curr_node->data );
}
child_node = curr_node->ptr[curr_direct];
} while ( !curr_node->thread[curr_direct]);
return( NULL );
}