| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 627 人关注过本帖
标题:请高手看看这个程序哪里错了
只看楼主 加入收藏
dreamsdark
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-1-29
收藏
 问题点数:0 回复次数:1 
请高手看看这个程序哪里错了
主要功能:创建二叉排序树,中序遍历,结点取3的模,0,1,2个各输出不同的值。 2003.
// mlyyytree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#define MAX 100
using namespace std;

typedef struct _ml_YYY_Node
{
   int data;
   struct _ml_YYY_Node * lc;
   struct _ml_YYY_Node * rc;
}ml_YYY_BTree;//定义树结点的结构体



//二叉排序树的类定义
class ml_YYY_CreateTree
{
public:
     ml_YYY_CreateTree(int r[],int n);
    
    virtual ~ml_YYY_CreateTree();
    void ml_YYY_InSert(ml_YYY_BTree * root , ml_YYY_BTree * s);//在二叉树中插入结点
    void mlYYYinOrder(ml_YYY_BTree * root);//中序遍历
private:
    ml_YYY_BTree * root;
    ml_YYY_BTree * s;  //二叉排序树的根指针
};


//插入操作
void ml_YYY_CreateTree:: ml_YYY_InSert(ml_YYY_BTree * root , ml_YYY_BTree * s)
{
    if(root == NULL)
    {
        root = s ;
    }
    else if(s->data < root->data)
    {
        ml_YYY_InSert(root->lc , s);
    }
    else
    {
        ml_YYY_InSert(root->rc , s);
    }
}





//二叉排序树的构造算法
 ml_YYY_CreateTree:: ml_YYY_CreateTree(int r[],int n)
{    
      ml_YYY_BTree * root = NULL;
      for(int i = 0;i < n;i++)
      {
          ml_YYY_BTree * s=(ml_YYY_BTree*)malloc(sizeof(ml_YYY_BTree));
          if(s == NULL)
          {
              cout<<"Not Enough Memory!\n" ;
          }
          else
          {
            s->data = r[i];
            s->lc = NULL;
            s->rc = NULL;
            ml_YYY_InSert( root , s);
          }
  }
}



//多态输出结果

class mlYYYshow
{
public:
    virtual void disPlay(int n);
private:
    int n;
};

class mlYYYcircleShow:public  mlYYYshow
{
 public:
    void disPlay(int n)
    {
        if(n%3 == 0)
        {
            cout<<"Circle-"<<endl;
        }
    }
};

class mlYYYtriangleShow:public  mlYYYshow
{
public:
    void disPlay(int n)
    {
        if(n%3 == 1)
        {
            cout<<"Triangle-"<<endl;
        }
    }
};

class mlYYYrectangleShow:public  mlYYYshow
{
public:
    void disPlay(int n)
    {
        if(n%3 == 2)
        {
            cout<<"Rectangle-"<<endl;
        }
    }
};





//树的中序遍历算法
void mlYYYinOrder(ml_YYY_BTree * root)
{
    if(root == NULL)
    {
        cout<<"the tree is null."<<endl;
    }
    else
    {
        mlYYYshow show;
        mlYYYinOrder(root->lc);
        show.disPlay(root->data);
        mlYYYinOrder(root->rc);

    }
}





void main()
{
  int i,n;
  int a[MAX];
  cout<<"intput the number of the ver "<<endl;
  cin >>n;
  cout<<"请输入数字构造二叉树:"<<endl;
  for(i=0;i<n;i++)
  {
      cin >> a[i] ;
      if(a[i] < 0 || !cin)
    {
        cout<<"输入有误,请重新输入数字:"<<endl;
        cin.clear(); //清除错误标记
        cin.get(); //清除输入缓冲区
      }
  }
   ml_YYY_BTree * Tree ;
   Tree = ml_YYY_CreateTree(a, n);
   cout<<"中序遍历树,输出如下:"<<endl;
   mlYYYinOrder(Tree);
}
编译的错误如下:
d:\Program Files\Microsoft Visual Studio .NET 2003\pro\2\2.cpp(166): error C2440: '=' : cannot convert from 'ml_YYY_CreateTree' to 'ml_YYY_BTree *'
搜索更多相关主题的帖子: YYY Node int 
2008-01-30 09:41
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
收藏
得分:0 
超过20行,又没注解,不想看.......

PS:现在QT的广告越做越大了
2008-01-30 15:25
快速回复:请高手看看这个程序哪里错了
数据加载中...
 
   



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

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