Ps: code approach from the way one's deceased father grind and online data supplement, watching the king code, found that the code is must misunderstanding, after consult online ideas, get inspiration to code - create a binary sort tree by inserting algorithm, the incoming parameters using the secondary pointer can effectively make the parameter changes the root node (the root)
Net some ideas for the insert algorithm using recursion lookup algorithm instead of inserting recursive
Nonsense not much said, directly on the code - (code concise absolutely not wordy, not including deleted, can begin)
The definition of the following is a data structure classes, can realize the c + + code, c code is not the one instance?)
//the Node Node class h
# pragma once
The class Node
{
Private:
Int m_data;
Public:
M_left_child Node * and * m_right_child;
//the Node (int data);
The Node (int data, Node * left_child=nullptr, Node * right_child=nullptr);
~ the Node ();
Void set_data (int data);
Const int get_data ();
};
//the Node. The CPP
# include "Node. H"
Node: : Node (int data, Node * left_child, Node * right_child)
: m_data (data), m_left_child (left_child), m_right_child (right_child) {}
Node: : ~ Node ()
{
The delete m_left_child;
The delete m_right_child;
M_left_child=nullptr;
M_right_child=nullptr;
}
Void Node: : set_data (int data)
{
M_data=https://bbs.csdn.net/topics/data;
}
Const int Node: : get_data ()
{
Return m_data;
}
//Sort_tree. H binary sort tree class
# pragma once
# include "Node. H"
The class Sort_tree
{
Private:
Node * m_tree;
Public:
Sort_tree ();
Arr Sort_tree (int * and an int size);
~ Sort_tree ();
The Node * get_tree () const;
Node * find_data (Node * temp, int data);
Void insert_data (Node * * temp, int data);
Void inorder_traversal Node * (temp);
};
Finally, don't copy and paste error, it is copied to the vs2019 you try ah, is that once vs. macro, mian. CPP on test pattern, the last of the last, again, vs2019 effective measurement, code written by himself, when reprint please indicate the original source, it is forbidden to throw homemade