首先是二叉搜索树的建立和操作
/*二叉搜索树 binary searching tree*/
class BST {
public:
BST() :root(NULL) {
}
void buildBST(vector<int> nums);
void printBST();
TreeNode* root;
private:
void insert(TreeNode* &root, int x);//第一个参数为引用
void inorderRecur(TreeNode* root);//递归中序遍历
};
void BST::insert(TreeNode* &node, int x)
{
if (node == NULL)
{
node = new TreeNode(x);
}
else
{
if (x < node-