Idea: the AVL Tree is a highly balanced binary search tree. Here, we want to clearly describe whether it is a search tree or a Balance Tree.
Struct treenode {struct treenode * left; struct treenode * right; int key ;}; // determine whether it is a binary search tree, second, determine whether it is a balanced bool isavl (treenode * root, int depth) {If (isbst (Root) & isbalance (root, & depth) return true; return false ;} // determine whether it is a binary search tree bool isbst (treenode * root) {If (root = NULL) return true; If (! Isbst (root-> left) return false; If (! Isbst (root-> right) return false; treenode * cur = root-> left; If (cur! = NULL) {While (cur-> right! = NULL) cur = cur-> right; if (root-> key <cur-> key) return false;} treenode * cur = root-> right; if (cur! = NULL) {While (cur-> left! = NULL) cur = cur-> left; If (root-> key> cur-> key) return false;} return true ;} // determine whether bool isbalance (treenode * root, int * depth) {If (root = NULL) {* depth = 0; return true;} int depthl, depthr; if (! Isbalance (root-> left, & depthl) return false; If (! Isbalance (root-> right, & depthr) return false; int diff = depthl-depthr; If (diff> 1 | diff <-1) return false; * depth = 1 + (depthl> depthr? Depthl: depthr); Return true ;}
Determine whether a binary tree is an AVL Tree