二叉搜索树的中序遍历

Inorder traversal of binary search tree

递归函数是如何工作的?在每种情况下,都是用 temp->left 和 temp->right 调用遍历 veing 还是所有 temp->left 调用后跟所有 temp->right 调用?请详细解释以下代码。

   void traverse(bst *temp)
  {   
       if(temp)
      {
          traverse(bst->left);
          printf("%d",temp->info);
          traverse(bst->right);
      }
  }

当你编辑你的代码时。所以根据那个 -

void traverse(bst *temp)  // function to traverse in a bst (parameter as root )
 {   
    if(temp)            // check temp (if not NULL then proceed)
     {
        traverse(bst->left);     // recursive call with root as left child and traverse left sub-tree till it goes to last node.
        printf("%d",temp->info); //  print value of data at current node
        traverse(bst->right);    // recursive call with root as right child and traverse right sub-tree till it goes to last node
     }
 }

traverse(bst->left); 通过此调用它转到左子树的最后一个节点,当 if 条件变为 false 它 returns 到上一个调用并打印值该节点然后执行下一个递归调用 traverse(bst->right); 并遍历当前根的右子树,直到 temp 变为 NULL.