这中场景题,真的得手绘出逻辑,然后找出所内含的数学规律。
这是一颗满二叉树,根为down,左子树为down,右子树为up,按照BTree的先右后左的中序策略可以从上到下打印出折痕。
void printInBTree(int cur, int height, bool down) {
if (cur > height)
return;
printInBTree(cur + 1, height, false);
cout << (down ? "down" : "up") << "\t";
printInBTree(cur + 1, height, true);
}
void printAllFolds(int N) {
printInBTree(1, N, true);//根节点面向是down
}