To determine whether a binary tree is balanced binary tree public class avltree{///Two Fork tree node definition public static class node{public int value;
Public Node left;
public Node right;
public Node (int data) {this.value=data; }//Determine whether a binary tree is a balanced binary tree (using the second order traversal of a binary tree) public static Boolean Isavl (Node head) {boolean[]res=new boolean[1]
;
Res[0]=true;
GetHeight (Head,1,res);
return res[0]; ///Recursive call gets the height of the subtree and whether it is a balanced binary tree public static int getheight (Node head,int level,boolean[]res) {if (head==null) {Retu
RN level;
}//Zuozi height int lh=getheight (head.left,level+1,res);
if (!res[0]) {return level;
}//Right subtree height int rh=getheight (head.right,level+1,res);
if (!res[0]) {return level;
}//Left/right subtree height difference if (math.abs (LH-RH) >1) {res[0]=false;
Return Math.max (LH,RH); public static void Main (string[] args) {/** 1 2 3 4 5 6 7 */Node head = New Node (1);
Head.left = new Node (2);
Head.right = new Node (3);
Head.left.left = new Node (4);
Head.left.right = new Node (5);
Head.right.left = new Node (6);
Head.right.right = new Node (7);
/** 1 2 4/Node Node=new node (1);
Node.left=new Node (2);
Node.left.left=new Node (4);
Node.right=new Node (3);
System.out.println (head) (ISAVL);
System.out.println (ISAVL (node)); }
}