Iterator
templatestruct __TreeIterator{ typedef BinTreeNode Node; typedef __TreeIterator Self; __TreeIterator() {} __TreeIterator(Node* node) :_node(node) {} Ref operator*() {assert( _node); return _node->_date;} Self& operator++() {assert(_node); if(_node->RightTag==Link) {Node* right=_node->rightchild; while (right&&right->LeftTag==Link) {right=right->leftchild;} _node=right;} else {_node=_node->rightchild;} return *this;} Self& operator++(int) {Self tmp(*this); ++(*this); return tmp;} Self& operator--() {assert(_node); if(_node->LeftTag=Link) {Node* left=_node->leftchild; while (left&&left->RightTag==Link) {left=left-> rightchild;} _node=left;} else {_node=_node->leftchild;} return *this;} bool operator!=(const Self s) const {return _node!=s._node;} Node* _no de;
T means type, Ref means reference, Ptr means pointer
The realization of the binary tree
The need to implement begin and end
< pre code_snippet_id="1930184" snippet_file_name="blog_20161015_2_5713547" name="code" class="cpp">template
Test case
p>
void test(){ int a1[10]={1,2,3,'#','#' ,4,'#','#',5,6}; BinTreet1(a1,10,'#'); t1.InOrderThead(); //t1.InOrder_NonR(); BinTree : :Iterator it=t1.Begin(); cout<