Inorder tree traversal: Which definition is correct?

前端 未结 14 1347
轮回少年
轮回少年 2020-12-24 03:42

I have the following text from an academic course I took a while ago about inorder traversal (they also call it pancaking) of a binary tree (not BST):

14条回答
  •  感动是毒
    2020-12-24 04:10

    Forget the definitions, it's so much easier to just apply the algorithm:

    void inOrderPrint(Node root)
    {
      if (root.left != null) inOrderPrint(root.left);
      print(root.name);
      if (root.right != null) inOrderPrint(root.right);
    }
    

    It's just three lines. Rearrange the order for pre- and post- order.

提交回复
热议问题