Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 表达式树的前序遍历_C++_Tree_Preorder - Fatal编程技术网

C++ 表达式树的前序遍历

C++ 表达式树的前序遍历,c++,tree,preorder,C++,Tree,Preorder,此函数用于打印表达式树的前序遍历 void PreOrder(Node root) { if (root) { cout<< root->data<<" "; PreOrder(root->left); PreOrder(root->right); } } 我应该如何解决它。您还需要使用对预排序的递归调用的结果: s += PreO

此函数用于打印表达式树的前序遍历

void PreOrder(Node root) {
    if (root)  
    {     
        cout<< root->data<<" "; 
        PreOrder(root->left); 
        PreOrder(root->right);
    } 
    
}

我应该如何解决它。

您还需要使用对
预排序的递归调用的结果:

s += PreOrder(root->left); 
s += PreOrder(root->right); 

您还需要使用对
PreOrder
的递归调用的结果:

s += PreOrder(root->left); 
s += PreOrder(root->right); 

递归调用返回的字符串会发生什么情况?是的。在main函数中,我知道递归调用返回的字符串会发生什么情况?是的。在主要功能上我做到了