怎么写一个求结点右兄弟的函数
数据结构吧
全部回复
仅看楼主
level 1
晓晓Alina 楼主
求结点的右兄弟RightSibling(T,e)
2013年06月20日 17点06分 1
level 3
struct Node
{
int data;
struct Node* lchild;
struct Node* rchild;
}
typedef struct Node* Root;
int RightSibling(Root t,Node* e,Node *r)//求得的右结点地址放在r里
{
int result = 0;
if( e->data < t->data )
{
result = RightSibling(t->lchilde,e,r);
if(result == 1) { r = t->rchild; }
return 0;
}
else if ( e->data > t->data )
{
result = RightSibling(t->rchilde,e,r);
if(result == 1) { r = null; }return 0;}
else if ( e->data == t->data)
{
if( t == e )
{return 1;}
else
{//假设构建二叉树的时候相同往左放
resule = RightSibling(t->lchilde,e,r);
if(result == 1) { r = t->rchild; }
return 0;
}
}
else if ( t == null ){r = null;return 0;}}
2013年06月21日 08点06分 2
1