From 9d363c72d64ef78590fecc191a43789e2ecfc6fb Mon Sep 17 00:00:00 2001 From: Xu Bai <1373953675@qq.com> Date: Thu, 11 Jul 2019 22:38:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _04.树/_a.二叉树顺序结构.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/_04.树/_a.二叉树顺序结构.c b/_04.树/_a.二叉树顺序结构.c index 459397b..5c84cf2 100644 --- a/_04.树/_a.二叉树顺序结构.c +++ b/_04.树/_a.二叉树顺序结构.c @@ -2,12 +2,12 @@ * @Author: Xu Bai * @Date: 2019-07-09 22:50:41 * @LastEditors: Xu Bai - * @LastEditTime: 2019-07-10 23:12:44 + * @LastEditTime: 2019-07-11 22:38:19 */ #include "stdlib.h" #include "stdio.h" #include "io.h" -#include "math.h" +#include "math.h" #define OK 1 #define ERROR 0 @@ -110,3 +110,35 @@ int BiTreeDepth(SqBiTree T) return j; } +/*TգeTĸOK򷵻ERRORe޶ */ +Status Root(SqBiTree T, ElemType *e) +{ + if (BiTreeEmpty(T)) + { + return ERROR; + } + else + { + *e = T[0]; + return OK; + } +} + +/*شeλã㣬 Ľֵ*/ +Status Value(SqBiTree T, Position p, ElemType e) +{ + /*㡢תΪ */ + int i = (int)powl(2, p.level - 1) + p.order - 2; + /*ҶӸǿֵ˫Ϊ */ + if (e != Nil && T[(i + 1) / 2 - 1] == Nil) + { + return ERROR; + } + /* ˫׸ֵҶӣգ */ + else if (e == Nil && (T[i * 2 + 1] != Nil || T[i * 2 + 2] != Nil)) + { + return ERROR; + } + T[i] = e; + return OK; +} \ No newline at end of file