CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  基础类

帮我看看这个关于二叉数的错误

楼主barbie123()2006-06-01 03:19:40 在 C++ Builder / 基础类 提问

我这样定义一个二叉数   BinaryTree   c;  
  编译时出现这样一个错误,:\study\data\zuoye\seventh\build.cpp(124)   :   error   C2955:   'BinaryTree'   :   use   of   class   template   requires   template   argument   list  
                  D:\study\data\zuoye\seventh\build.cpp(52)   :   see   declaration   of   'BinaryTree'  
  高手帮我看看怎么回事啊?  
  以下是我的原程序  
  #include<iostream>  
  #include<fstream>  
  using   namespace   std;  
  int   j=1;  
  template<class   T>   class   BinaryTree;  
  template<class   T>  
  class   BinaryTreeNode  
  {  
  friend   class   BinaryTree<T>;  
  public:  
  BinaryTreeNode()   {LeftChild=RightChild=0;}  
  BinaryTreeNode(const   T&   e)  
  {data=e;LeftChild=RightChild=0;}  
  BinaryTreeNode(const   T&   e,BinaryTreeNode   *l,BinaryTreeNode   *r)  
  {data=e;LeftChild=l;RightChild=r;}  
  private:  
  T   data;  
  BinaryTreeNode<T>   *LeftChild,*RightChild;  
  };  
  template<class   T>  
  class   BinaryTree  
  {  
  public:  
  BinaryTree()   {root=0;};  
  ~BinaryTree(){};  
  bool   Empty()   const  
  {return   ((root)?   false:true);}  
  bool   Root(T   &x)   const;  
  void   MakeTree(const   T&   element,  
  BinaryTree<T>&   left,BinaryTree<T>&   right);  
  void   BreakTree(T&   element,BinaryTree<T>&   left,  
  BinaryTree<T>&   right);  
  void   PreOrder(void(*   Visit)(BinaryTreeNode<T>   *u))  
  {PreOrder(Visit,root);}  
  void   InOrder(void(*   Visit)(BinaryTreeNode<T>   *u))  
  {InOrder(Visit,root);}  
  void   PreOutput()   {PreOrder(Output,root);   out<<endl;}  
  void   InOutput()   {InOrder(Output,root);   out<<endl;}  
  void   Delete()   {PostOrder(Free,root);   root=0;}  
  void   creattree(int   n,int   *a,BinaryTreeNode<T>   *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);  
  static   void   Tree(BinaryTreeNode<T>   *t)   {delete   t;}  
  static   void   Output(BinaryTreeNode<T>   *t)  
  {out<<t->data<<'   ';}  
  static   void   Add1(BinaryTreeNode<T>   *t)   {count++;}  
  int   Height(BinaryTreeNode<T>   *t)   const;  
  };  
  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>&   right)  
  {  
  root=new   BinaryTreeNode<T>(element,left.root,left.root);  
  left.root=right.root=0;  
  }  
  template<class   T>  
  void   BinaryTree<T>::creattree(int   n,int   *a,BinaryTreeNode<T>   *root)  
  {  
  *root=new   BinaryTreeNode<T>(a[j++]);  
  if(j<=n){  
  creattree(n,a,&(*root)->leftchild);  
  creattree(n,a,&(*root)->rightchild);  
  }  
  }  
   
   
   
   
  template<class   T>  
  void   BinaryTree<T>::BreakTree(T&   element,BinaryTree<T>&   left,BinaryTree<T>&   right)  
  {  
  if(!   root)   throw   BadInput();  
  element=root->data;  
  left.root=root->LeftChild;  
  right.root=root->RightChild;  
  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->LeftChild);  
  PreOrder(Visit,t->RightChild);  
  }  
  }  
  template<class   T>  
  void   BinaryTree<T>::InOrder(void(*Visit)(BinaryTreeNode<T>   *u),BinaryTreeNode<T>   *t)  
  {  
  if(t){InOrder(Visit,t->LeftChild);  
  Visit(t);  
  InOrder(Visit,t->RightChild);  
  }  
  }  
  template<class   T>  
  int   BinaryTree<T>::Height(BinaryTreeNode<T>   *t)   const  
  {  
  if(!t)   return   0;  
  int   hl=Height(t->LeftChild);  
  int   hr=Height(t->RightChild);  
  if(hl>hr)   return   ++hl;  
  else   return   ++hr;  
  }  
   
  int   main()  
  {  
  ifstream   in("input.txt");  
  ofstream   out("output.txt");  
  int   i,*a,n;  
  cin>>n;  
  a=new   int   (n+1);  
  a[0]=0;  
  for(i=1;i<=n;i++)  
  {a[i]=i;}  
  BinaryTree   c;  
   
   
   
   
   
   
   
  }  
   
  问题点数:10、回复次数:1Top

1 楼xpdavis(咕嘟-不想孤独)回复于 2006-06-01 07:41:29 得分 0

BinaryTree   c;  
  -------->  
  BinaryTree<int>   c;  
  或其它类型Top

相关问题

关键词

得分解答快速导航

  • 帖主:barbie123

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo