Binary Search Tree - PrintInOrder ();

3

My BST (templated class) has the function PrintInOrder() , which does not receive parameters:

void BST<Type>::printInOrder() const{}

I've been searching the internet, and found a few InOrder() , however they get a Node* to the root as a parameter, which makes sense.

How could I do a recursion in the function I quoted without passing parameters? Is there a way for me to create a private member in the class as an aid to this?

My BST 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;
};
    
asked by anonymous 13.02.2016 / 09:14

1 answer

3

What I said in my comment would be this:

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;
void printInOrderRecursive(Node* root);

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();
};

Since the implementation of void printInOrder(); would be:

void printInOrder() {
    printInOrderRecursive(m_root);
}

I did not put the implementation of void printInOrderRecursive(Node* root); , because you said in the question already found.

    
13.02.2016 / 14:16