Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.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++ 二叉搜索树-PrintInOrder();_C++_Binary Search Tree - Fatal编程技术网

C++ 二叉搜索树-PrintInOrder();

C++ 二叉搜索树-PrintInOrder();,c++,binary-search-tree,C++,Binary Search Tree,在我的BST模板类中,有一个PrintInOrder函数不接受任何参数 void BST<Type>::printInOrder() const{} 只需让printInOrder函数调用具有节点指针参数的helper函数 要限制辅助函数的范围,它可以是 BST类的私有静态成员,或 命名空间中的一个命名空间范围无关函数,称为impl或detail或此类约定,用于私有实现部分,甚至 printInOrder函数内部类中的静态函数 当然,您可以只维护显式堆栈并使用迭代解决方案,而不需要

在我的BST模板类中,有一个PrintInOrder函数不接受任何参数

void BST<Type>::printInOrder() const{}
只需让printInOrder函数调用具有节点指针参数的helper函数

要限制辅助函数的范围,它可以是

BST类的私有静态成员,或

命名空间中的一个命名空间范围无关函数,称为impl或detail或此类约定,用于私有实现部分,甚至

printInOrder函数内部类中的静态函数

当然,您可以只维护显式堆栈并使用迭代解决方案,而不需要使用递归实现功能,在这种情况下,您不需要帮助函数


一般建议:通过保留宏的所有大写名称,可以避免麻烦的意外文本替换,以及避免给人以叫喊的印象。这是一个常见的C++约定。< /P>他的函数的可能副本将根作为参数传递。我想找出一个不带参数的函数
/* I don't know if it's gonna help, but this is my class */

struct Node
{
    Type m_data;
    Node *m_left, *m_right;

    Node(const Type& _data) : m_data(_data), m_left(nullptr), m_right(nullptr) {}
};

Node* m_root;
int m_size;

public:
    BST();
    ~BST();
    BST& operator=(const BST& that);
    BST(const BST& that);;
    void insert(const Type& v);
    bool findAndRemove(const Type& v);
    bool find(const Type& v) const;
    void clear();
    void printInOrder() const;
};