image.png
    这中场景题,真的得手绘出逻辑,然后找出所内含的数学规律。
    image.png
    这是一颗满二叉树,根为down,左子树为down,右子树为up,按照BTree的先右后左的中序策略可以从上到下打印出折痕。

    1. void printInBTree(int cur, int height, bool down) {
    2. if (cur > height)
    3. return;
    4. printInBTree(cur + 1, height, false);
    5. cout << (down ? "down" : "up") << "\t";
    6. printInBTree(cur + 1, height, true);
    7. }
    8. void printAllFolds(int N) {
    9. printInBTree(1, N, true);//根节点面向是down
    10. }