DeleteChild(BiTree *T, BiTree p, int flag)//删除值为p的节点的子树,flag=1删除右子树,flag=0删除左子树
154 {
155 BiTree tar;
156
157 tar = Search(*T, p->data);
158 if (tar == NULL)
159 return ERROR;
160 if (flag == 0)
161 {
162 ClearBiTree(&(tar->lchild));
163 tar->lchild = NULL;
164 }
165 else
166 {
167 ClearBiTree(&(tar->rchild));
168 tar->rchild = NULL;
169 }
170 return OK;
171 }
172
173
174 BiTree Parent(BiTree T, Type e)//返回值为e的节点的父母
175 {
176 BiTree cur;
177
178 if (T == NULL)
179 return NULL;
180 else
181 {
182 if ((T->lchild)->data == e || (T->rchild)->data == e)
183 cur = T;
184 else
185 {
186 cur = Parent(T->lchild, e);
187 if (cur == NULL)
188 cur = Parent(T->rchild, e);
189 }
190 }
191 return cur;
192 }
193
194 BiTree LeftChild(BiTree T, Type e)//返回左孩子
195 {
196 BiTree result;
197
198 if (T == NULL)
199 return NULL;
200 else
201 {
202 if (T->data == e)
203 return T->lchild;
204 else
205 {
206 result = LeftChild(T->lchild, e);
207 if (result == NULL)
208 result = LeftChild(T->rchild, e);
209 }
210 }
211 return result;
212 }
213
214 BiTree LeftSibling(BiTree T, Type e)//返回左兄弟
215 {
216 BiTree result;
217
218 if (T->lchild == NULL || T->rchild == NULL)
219 return NULL;
220 else
221 {
222 if (T->lchild->data == e && T->rchild)
223 return T->rchild;
224 else
225 {
226 result = LeftSibling(T->lchild, e);
227 if (result == NULL)
228 result = LeftSibling(T->rchild, e);
229 }
230 }
231 return result;
232 }
233
234 int main()
235 {
236 BiTree T;
237 BitNode root;
238 BiTree temp;
239 int depth;
240
241 CreatBiTree(&T);
242 //ClearBiTree(&T);
243 //depth = BiTreeDepth(T);
244 //root = Root(T);
245 //InserInc(&T, 'd');
246 //temp = Search(T, 'a');
247 //Delete(&T, 'd');
248 //DeleteChild(&T, temp, 1);
249 //temp = Parent(T, 'c');
250 temp = LeftSibling(T, 'a');
251 return 0;
252 }