http://zhedahht.blog.163.com/blog/static/25411174200725319627/
#include <cstdio> #include <cstdlib> #include <cstring> bool verify_bft_squence(int a[], int s, int e) { if (a == NULL || s > e) return false; if (s == e) return true; int i; for (i = s; i <= e; ++i) if (a[i] > a[e]) break; int j; for (j = i; j <= e; ++j) if (a[j] < a[e]) return false; bool left = true; if (s <= i-1) left = verify_bft_squence(a, s, i-1); bool right = true; if (i <= e - 1) right = verify_bft_squence(a, i, e - 1); return (left && right); } int main() { int a[10] = {0, 5, 7, 6, 9, 11, 10, 8}; bool flag = verify_bft_squence(a, 1, 7); return 0; }