From e3caad7cdec5bf47886f4486c8c696ff752540d3 Mon Sep 17 00:00:00 2001 From: xusun0623 <45837271+xusun0623@users.noreply.github.com> Date: Fri, 25 Feb 2022 10:13:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E2022=E5=B9=B4=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2022_binary_tree.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 2022_binary_tree.cpp diff --git a/2022_binary_tree.cpp b/2022_binary_tree.cpp new file mode 100644 index 0000000..eb824ad --- /dev/null +++ b/2022_binary_tree.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#define MaxSize 100 + +typedef struct { + int Sqlistdata[MaxSize]; + int num; +} Sqlist; + +bool T = true; +void inorder(Sqlist a, int i) { + if (i >= a.num || a.Sqlistdata[i] == -1 || !T) { + return; + } + int k = a.Sqlistdata[i]; + inorder(a, i * 2 + 1); + if (k < a.Sqlistdata[i * 2 + 1]) { + T = false; + return; + } + inorder(a, i * 2 + 2); +} + +int main() { + Sqlist s = Sqlist(); + int a[] = {4, 2, 6, 1, 3, 5, 7}; //高度为3的满二叉排序树 + s.num = 7; + for (int i = 0; i < s.num; i++) { + s.Sqlistdata[i] = a[i]; + } + inorder(s, 0); + printf(T ? "是二叉搜索树" : "不是二叉搜索树"); + return 0; +}