简体   繁体   English

C ++中的二叉树有序遍历

[英]binary tree inorder traversal in C++

I'm trying to print out a binary tree I've build using inorder traversal, but I'm having trouble on defining how to pass values to the recursive function. 我正在尝试打印出使用顺序遍历构建的二叉树,但是在定义如何将值传递给递归函数时遇到了麻烦。 Here is the error I'm getting: 这是我得到的错误:

1>methods.obj : error LNK2001: unresolved external symbol "public: void __thiscall morsecode::in_order(struct letter *)" (?in_order@morsecode@@QAEXPAUletter@@@Z) 1> methods.obj:错误LNK2001:未解析的外部符号“ public:void __thiscall morsecode :: in_order(结构字母*)”(?in_order @ morsecode @@ QAEXPAUletter @@@@ Z)

Here's my tree from my header file: 这是我的头文件中的树:

struct letter
{
    string let;
    string morse;
    letter *left;
    letter *right;
};

Method from source file: 源文件中的方法:

void in_order(struct letter *P)
    {
        if(P==NULL) return;
        in_order(P->left);
        cout<<"letter: "<<P->let<<endl;
        in_order(P->right);
    }

Am I missing something important here? 我在这里错过了重要的事情吗?

Perhaps you need: 也许您需要:

void morsecode::in_order(struct letter *P) {
     if(P==NULL) return;
     in_order(P->left);
     cout<<"letter: "<<P->let<<endl;
     in_order(P->right);
}

to be a member of the morsecode class. 成为morsecode类的成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM