搜索二叉树
代码说明:
#pragma once template struct Node { T _data; Node* left; Node* right; Node(T val) :_data(val), left(NULL), right(NULL) {} ~Node() {} }; template class BinSearchTree { public: BinSearchTree() :_root(0) {} void CreatTree(char* str) { int n = strlen(str); CreatTree_(_root,str,n); } void comFather(char a,char b) { return comFather_(_root,a,b); } protected: void comFather_(Node* root,char a,char b) { if (root->_data > a && root->_data < b) { cout _data _data > a && root->_data > b) comFather_(root->left, a, b); if (root->_data < a && root->_data < b) comFather_(root->right, a, b); } void insertVal(Node*& root, char ch) { if (root == NULL) { root = new Node(ch); return;
下载说明:请别用迅雷下载,失败请重下,重下不扣分!