您当前的位置: 百科371电脑/网络其他编程 → 电脑/网络内容 退出登录 用户管理 用户注册
本类热门文章
相关文章
中原建材网
哪位大侠帮忙写个main函数

减小字体 增大字体

问题:#include<iostream.h>int max(int a,int b) //比大小函数{ return a>b?a:b;}template<class type> // 二叉树的前视定义class bin_tree;template<class type> //二叉树节点的定义class bin_tree_node{ friend class bin_tree<type>; private: type data; //数据域 bin_tree_node<type>* left_child; //指向左子女的指针 bin_tree_node<type>* right_child; //指向右子女的指针 public: bin_tree_node() //构造函数及其重载 { left_child=right_child=NULL; } bin_tree_node(type value,bin_tree_node<type>* l=NULL,bin_tree_node<type>* r=NULL) { left_child=l; right_child=r; data=value; }};template<class type> //二叉树类的定义class bin_tree{ private: bin_tree_node<type>* root; //根节点的指针 type ref_value; //数据输入停止的标志,仅用于输入 void destroy(bin_tree_node<type>* current); //从current开始销毁二叉树 public: bin_tree(type value) //构造函数 { ref_value=value; root=NULL; } virtual ~bin_tree() //析构函数,使用destroy() { destroy(root); } int size(bin_tree_node<type>* t); //返回树的节点数 int height(bin_tree_node<type>* t); //返回树的高度 void exchange(bin_tree_node<type>* t); //交换左右子女的细化 void exchange() //交换左右子女 { exchange(root); }};//以下为成员函数和友元函数的定义template<class type>void bin_tree<type>::destroy(bin_tree_node<type>* current) //销毁函数{ if(current!=NULL) { destroy(current->left_child); destroy(current->right_child); delete current; }}template<class type> //返回树的节点数int bin_tree<type>::size(bin_tree_node<type>* t){ if(t==NULL) return 0; else return 1+size(t->left_child)+size(t->right_child);}template<class type> //返回树的高度int bin_tree<type>::height(bin_tree_node<type>* t){ if(t==NULL) return -1; else return 1+max(height(t->left_child),height(t->right_child));}template<class type> //交换左右子女的细化函数void bin_tree<type>::exchange(bin_tree_node<type>* t){ if(t->left_child!=NULL) exchange(t->left_child); if(t->right_child!=NULL) exchange(t->right_child); if(t->left_child!=NULL&&t->right_child!=NULL) { bin_tree_node<type>* temp; temp=t->left_child; t->left_child=t->right_child; t->right_child=temp; }}要求实现删除,左右孩子互换和计算树高  

这是什么、?

如果你对#include<iostream.h>int max(int a,int b) //比大小函数{ return a>b?a:b;}template<class type> // 二叉树的前视定义class bin_tree;template<class type> //二叉树节点的定义class bin_tree_node{ friend class bin_tree<type>; private: type data; //数据域 bin_tree_node<type>* left_child; //指向左子女的指针 bin_tree_node<type>* right_child; //指向右子女的指针 public: bin_tree_node() //构造函数及其重载 { left_child=right_child=NULL; } bin_tree_node(type value,bin_tree_node<type>* l=NULL,bin_tree_node<type>* r=NULL) { left_child=l; right_child=r; data=value; }};template<class type> //二叉树类的定义class bin_tree{ private: bin_tree_node<type>* root; //根节点的指针 type ref_value; //数据输入停止的标志,仅用于输入 void destroy(bin_tree_node<type>* current); //从current开始销毁二叉树 public: bin_tree(type value) //构造函数 { ref_value=value; root=NULL; } virtual ~bin_tree() //析构函数,使用destroy() { destroy(root); } int size(bin_tree_node<type>* t); //返回树的节点数 int height(bin_tree_node<type>* t); //返回树的高度 void exchange(bin_tree_node<type>* t); //交换左右子女的细化 void exchange() //交换左右子女 { exchange(root); }};//以下为成员函数和友元函数的定义template<class type>void bin_tree<type>::destroy(bin_tree_node<type>* current) //销毁函数{ if(current!=NULL) { destroy(current->left_child); destroy(current->right_child); delete current; }}template<class type> //返回树的节点数int bin_tree<type>::size(bin_tree_node<type>* t){ if(t==NULL) return 0; else return 1+size(t->left_child)+size(t->right_child);}template<class type> //返回树的高度int bin_tree<type>::height(bin_tree_node<type>* t){ if(t==NULL) return -1; else return 1+max(height(t->left_child),height(t->right_child));}template<class type> //交换左右子女的细化函数void bin_tree<type>::exchange(bin_tree_node<type>* t){ if(t->left_child!=NULL) exchange(t->left_child); if(t->right_child!=NULL) exchange(t->right_child); if(t->left_child!=NULL&&t->right_child!=NULL) { bin_tree_node<type>* temp; temp=t->left_child; t->left_child=t->right_child; t->right_child=temp; }}要求实现删除,左右孩子互换和计算树高这个问题有好的意见或 建议,请留言
[] [返回上一页] [打 印]
电脑/网络评论 (评论内容只代表网友观点,与本站立场无关!)

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码

中原建材网 简单版 站长QQ:382546553