Import java.util.*;
Determine if the binary tree is a search binary tree and complete binary tree the public class istree{//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 if Search binary tree (in-sequence traversal increment) public static Boolean Isbst (Node head) {if (head==null) {RE
Turn true;
Boolean res=true;
Node Pre=null;
Node Cur1=head;
Node Cur2=null;
while (cur1!=null) {cur2=cur1.left;
if (Cur2!=null) {while (CUR2.RIGHT!=NULL&&CUR2.RIGHT!=CUR1) {
Cur2=cur2.right;
} if (cur2.right==null) {cur2.right=cur1;
Cur1=cur1.left;
Continue
}else {cur2.right=null;
} } if (Pre!=null&&pre.value>cur1.value) {res=false;
} Pre=cur1;
Cur1=cur1.right;
return res; //To determine if it is a complete binary tree/** (1) Sequence traversal of all nodes (2) The current node has a right child, no left child false (3) The current node is not all children have, then the leaf node, otherwise false/P
Ublic Static Boolean ISCBT (Node head) {if (Head==null) {return true;
} queue<node>queue=new linkedlist<node> ();
Boolean leaf=false;
Node L=null;
Node R=null;
Queue.offer (head);
while (!queue.isempty ()) {head=queue.poll ();
L=head.left;
R=head.right; if (leaf&& (l!=null| | r!=null)) | |
(L==null&&r!=null))
{return false;
} if (L!=null) {queue.offer (L);
} if (R!=null) {Queue.offer (R); } else
{leaf=true;
} return true; public static void Main (String []args) {/** 4 2 6 1
3 5 */Node Head=new node (4);
Head.left=new Node (2);
Head.right=new Node (6);
Head.left.left=new Node (1);
Head.left.right=new Node (3);
Head.right.left=new Node (5);
System.out.println (head) (ISBST);
System.out.println (head) (ISCBT); }
}