正在加载图片...
template <class Type> void Binary Tree<type> Traverse( Bin TreeNode Type>* current, ostream out )const /有函数:先序遆历输出根指针为 current二叉树的所有结点的值 if( current!=NUL)年空树则遍历输出 out<< current-data<<;∥输出根结点的值 Traverse( current- leftchild,out);/历输出左子树 Traverse( current-> right Child,out);∥)历输出右子树 template <class Type> ostream operator<<(ostream &out Binary Tree<Type>& Tree 重载 Inserting操作符“≤”,用于直接输出一棵二叉树 out<<"Preorder traversal of binary tree. n Tre. Traverse(Tree.Root,out);∥/先序遍历输出 out << endl return out 20212222021/2/22 15 template <class Type> void BinaryTree<Type> :: Traverse ( BinTreeNode < Type> * current , ostream & out ) const //私有函数:先序遍历输出根指针为current 二叉树的所有结点的值 { if ( current != NULL ) //非空树则遍历输出 { out << current -> data << ‘ ‘ ; //输出根结点的值 Traverse ( current -> leftChild , out ) ; //遍历输出左子树 Traverse ( current -> rightChild , out ) ; //遍历输出右子树 } } template <class Type> ostream & operator << ( ostream & out , BinaryTree<Type> & Tree ) //重载inserting 操作符“ << ” , 用于直接输出一棵二叉树 { out << “Preorder traversal of binary tree. \n” ; Tree . Traverse ( Tree . Root , out ) ; //先序遍历输出 out << endl ; return out ; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有