鲁班软件笔试时的题目,后来搜了下,发现是软设的题。
转自:http://hi.baidu.com/mqgw/blog/item/cade830f1894222c6159f36c.html
转自:http://www.examda.com/soft/Programmer/060124/091040110-2.html
函数DeleteNode(Bitree *r,int e)的功能是:在树根结点指针为r的二叉查找(排序)树上删除键值为e的结点,若删除成功,则函数返回0,否则函数返回-1。二叉查找树结点的类型定义为: struct Tnode *Lchild,*Rchild; }*Bitree;
{ /*从树根结点出发查找键值为e的结点*/ if ( e< p->data) p = p -> Lchild; p = p->Rchild; } { /* 处理情况3 */ pp = p; { pp = s; s = s-> Rchild; } p = s; } c = p -> Lchild; else c = p -> Rchild; *r = c; if (p==pp->Lchild ) pp -> Lchild = c; pp->Rchild = c; return 0; } |