面试题06 判断二叉树后序遍历的结果 [树]

人理解迭代,神请你来理解递归! 同样的道理 : 大问题拆成小问题,小问题再继续拆,最后一个出口然后全部解决,出口正是最小的子问题的边界处理!
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <iterator>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <climits>
#include <cassert>
#define BUG puts("here!!!");

using namespace std;
const int N = 105;
class Node {
public :
	int value;
	Node* lchild;
	Node* rchild;
};
bool res(int *sec, int len) {
	if(sec == NULL || len <= 0) return false;
	int root = sec[len-1];
	int i = 0;
	for(; i < len-1; i++) {
		if(sec[i] > root) {
			break;
		}
	}
	for(; i < len-1; i++) {
		if(sec[i] < root) return false;
	}
	bool left = true;
	if(i > 0) {
		left = res(sec, i);
	}
	bool right = true;
	if(i < len-1) {
		right = res(sec+i, len-i-1);
	}
	return (left && right);
}
int main() {
	return 0;
}

原文地址:https://www.cnblogs.com/robbychan/p/3787170.html