
int InsertNode ( NodeType **t,KeyType kx )
{ /*在二叉排序树*t 上插入关键码为kx 的结点*/
NodeType *p=*t,*q,*s;
int flag=0;
if ( !SearchElem ( *t,&p,&q,kx ) ); /*在*t 为根的子树上查找*/
{
s= ( NodeType * ) ) malloc ( sizeof ( NodeType ) ); /*申请结点,并赋值*/
s->elem.key=kx; s->lc=NULL; s->rc=NULL;
flag=1; /*设置插入成功标志*/
if ( !p ) t=s; /*向空树中插入时*/
else
{
if ( kx>p->elem.key ) p->rc=s; /*插入结点为p 的右子女*/
else p->lc=s; /*插入结点为p 的左子女*/
}
}
return flag;
}


