分类:
2010-02-01 15:34:39
|
|
#include
T_Tree * BB_Tree_Add( T_Tree *sp,void *content,int len,
int (*Cmp_rec)(void *sp_content,void *content,int len),
int (*user_add_tree)(T_Tree *sp,void *content,int len));
功能: BB_Tree_Add:将内容加到树
参数:
sp:根节点,content:节点内容,可以是任何数据结构,在树中重新分配空间复制其内容。
len:content的长度, Cmp_rec:记录比较器,content>sp_content时返回>0,
<时返回<0,=时返回0。
user_add_tree插入节点时重码后的处理程序a
返回值:新的根节点
int BB_Tree_Scan(T_Tree *sp, int (*proc)(void *content));
功能:遍历树。
参数:sp根节点。proc:找到节点后的处理程序,这些程序返回0则继续遍历,非0终止遍历。
返回值:proc的返回值。
void BB_Tree_Free(T_Tree **sp,void (*user_free)(void *val));
功能:删除树。
参数:sp:根节点的指针。user_free删除前处理content的函数,可以为0.。
T_Tree * BB_Tree_Find(T_Tree *sp,void *content_key,int len,
int (*Cmp_rec)(void *sp_content,void *content_key,int len));
功能:在树中查找节点。
参数:sp根节点。content_key:内容,其中含有键值。Cmp_rec:比较函数。
len:content_key的长度,
返回值:找到的节点,找不到为0;
T_Tree * BB_Tree_Del(T_Tree *tp,void *content_key,int size_key,
int (*Comp)(void *node,void *content,int size_content),
int (*user_free)(void *content),int *flg);
功能:删除指定节点,返回新的根节点。
参数:tp 根节点。content_key:内容,其中含有键值。
Size_key:content_key的长度,
Comp:比较函数。
user_free删除前处理content的函数,可以为0.返回0表示用户处理删除成功,否则用户处理失败,该节点将不被删除。
flg标志地址,初值为0.返回后,0表示删除未成功,其他表示在第几层删除成功。
返回值:新的根节点。