#include <iostream>using namespacestd;BOOLIspostorderofbst (intPostorder[],intLowintHigh ) { if(Postorder = = NULL | | Low <0|| High <0)return false; if(Low = = high)return true; intPivot = high-1;//find the dividing point of the Zuozi and right sub-tree while(Pivot >=0&& Postorder[pivot] >Postorder[high]) { --pivot; } intLowindex =pivot; while(Lowindex >=0&& Postorder[lowindex] <Postorder[high]) { --Lowindex; } if(Lowindex >=0)return false;//left dial hand tree all elements are smaller than the root node if(Pivot +1< high &&!ispostorderofbst (postorder, pivot +1, High-1))//Judging right sub-tree { return false; } if(Low <= pivot &&!ispostorderofbst (postorder, Low, pivot))//Judging the left sub-tree { return false; } return true;}intMainintargcChar Const*argv[]) { intPostorder0[] = {5,7,6,9, One,Ten,8}; intPostorder1[] = { One,Ten,9,8,7,6,5}; intPostorder2[] = {5,6,7,8,9,Ten, One}; intPostorder3[] = {8,9,5, One,Ten,7,6}; intPostorder4[] = {7,6, A,5, One,Ten,9}; cout<<"{5, 7, 6, 9, one, ten, 8}---"<< Ispostorderofbst (Postorder0,0,6) <<Endl; cout<<"{One, ten, 9, 8, 7, 6, 5}---"<< Ispostorderofbst (Postorder1,0,6) <<Endl; cout<<"{5, 6, 7, 8, 9, ten, one}---"<< Ispostorderofbst (Postorder2,0,6) <<Endl; cout<<"{8, 9, 5, one, ten, 7, 6}---"<< Ispostorderofbst (Postorder3,0,6) <<Endl; cout<<"{7, 6, A, 5, one, ten, 9}---"<< Ispostorderofbst (Postorder4,0,6) <<Endl; return 0;}
Determines whether the array sequence is a sequential traversal of a two-fork search tree