Analysis:
Code:
PackageTree; Public class verifybst { //First element subscript low, last element subscript high Public Static Boolean Verifysequencebst(int[] sequence,intLowintHigh) {if(Sequence = =NULL|| High-Low <0){return false; }introot = Sequence[high];intIThe node of the left sub-node of the binary search tree is smaller than the root junction . for(i=low;i//If the value is greater than the root node, stop, indicating that the subscript starts with the right subtree . if(Sequence[i]>root) { Break; } }//i=3 //The node in the right sub-number of the binary search tree is greater than the root node . for(intJ=i; J < High; J + +) {if(Sequence[j]<root) {return false; } }//Determine if the left subtree is a binary search number Booleanleft =true;if(i>0) {left = Verifysequencebst (sequence,0. io1); }//Determine if the right subtree is a binary search number Booleanright =true;if(I1, high); }return(Left&&right); } Public Static void Main(string[] args) {int[] arr = {5,7,6,9, One,Ten,8};BooleanFlag =verifysequencebst (arr,0, arr.length-1); SYSTEM.OUT.PRINTLN (flag);int[] arr1 = {7,4,6,5};BooleanFlag1 = Verifysequencebst (arr1,0, arr1.length-1); System.out.println (FLAG1); }}
Operation Result:
truefalse
Determine if an array is a sequential traversal of a two-fork search tree (Java)