| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 737 人关注过本帖
标题:关于2差树
只看楼主 加入收藏
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
 问题点数:0 回复次数:2 
关于2差树

#include "iostream"
using namespace std;

template<class T>
class BinaryTree;
template<class T>
class BinaryTreeNode
{
friend class BinaryTree<T>;
friend void visit(BinaryTreeNode<T> *);
public:
BinaryTreeNode() { left = right = 0 ;}
BinaryTreeNode(const T& e){ data = e; left=right=0;}
BinaryTreeNode(const T& e,BinaryTreeNode *l,BinaryTreeNode *r)
{
data = e;
left = l;
right = r;
}
private:
T data;
BinaryTreeNode<T> *left;
BinaryTreeNode<T> *right;
};

template<class T>
class BinaryTree
{
public:
BinaryTree() { root = 0; };
~BinaryTree(){};
bool isEmpty() const { return ((root)?false:true);}
bool Root(T&x) const;
void makeTree(const T& element,BinaryTree<T> &left, BinaryTree<T>& rigth);
void breakTree( T&element, BinaryTree<T> &left, BinaryTree<T> & rigth);
void preOrder( void(*visit)(BinaryTreeNode<T> *u))
{
preOrder(visit,root);
}

void inOrder( void(*visit) (BinaryTreeNode<T> *u))
{
inOrder(visit,root);
}
private:
BinaryTreeNode<T> *root;
void preOrder( void(*visit)(BinaryTreeNode<T> *u), BinaryTreeNode<T> *t);
void inOrder( void(*visit)(BinaryTreeNode<T> *u), BinaryTreeNode<T> *t);
};

template<class T>
bool BinaryTree<T>::Root(T &x) const
{
if(root)
{
x = root->data;
return true;
}
else return false;
}

template<class T>
void BinaryTree<T>::makeTree(const T&element, BinaryTree<T> &left, BinaryTree<T> & rigth)
{
root = new BinaryTreeNode<T>(element,left.root,rigth.root);
left.root = right.root = 0;
}

template<class T>
void BinaryTree<T>::breakTree( T &element, BinaryTree<T> &left, BinaryTree<T> & rigth)
{
if(!root) { cout<<"空树"<<endl; exit(1); }
element = root->data;
left.root = root->left;
rigth.root = root->right;
delete root;
root = 0;
}
//先序列遍历二叉树
template<class T>
void BinaryTree<T>::preOrder( void(*visit)(BinaryTreeNode<T> *u), BinaryTreeNode<T> *t)
{
if(t)
{
visit(t);
preOrder(visit,t->left);
preOrder(visit,t->right);
}
}
//中序列遍历二叉树

template<class T>
void BinaryTree<T>::inOrder(void(*visit)(BinaryTreeNode<T> *u),BinaryTreeNode<T> *t)
{
if(t)
{
inOrder(visit,t->left);
Visit(t);
inOrder(visit,t->right);
}
}
/*
int count = 0;
BinaryTree<int> a,x,y,z;
template<class T>
void ct(BinaryTreeNode<T> *t) { count++;}
int main()
{

y.makeTree(1,a,a);
z.makeTree(2,a,a);
x.makeTree(3,y,z);
y.makeTree(4,x,a);
y.preOrder(ct);
cout<< count <<endl;
system("pause");
return 0;
}
*/

哪里语法出错了

[此贴子已经被作者于2005-11-4 12:46:55编辑过]

搜索更多相关主题的帖子: private include public friend visit 
2005-11-03 23:57
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
收藏
得分:0 
BinaryTreeNode<T> *left;
这不是一个普通的变量是一个类吧,
你使用了,A=B=C这种形式的赋值,但是没有看见你对
BinaryTreeNode<T>的= 操作符进行重载。
所以就有错误了

这个数据结构,我还是没有学习。所以程序是改不了了,
但是这个程序一编译有n个警告与错误
提醒注意

http://kongfuziandlife. http://codeanddesign.
2005-11-04 10:56
想你的天空
Rank: 2
等 级:新手上路
威 望:5
帖 子:610
专家分:0
注 册:2004-12-30
收藏
得分:0 

哪位大侠帮我看下好吗


2005-11-04 12:48
快速回复:关于2差树
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021933 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved