| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:一切都正常,只在最后一步运行出不能读
只看楼主 加入收藏
iambeliveble
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-9-2
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
一切都正常,只在最后一步运行出不能读
#include<iostream.h>
 template<class T>
     struct BiNode
 {
     T data;
     BiNode<T> *lchild,*rchild;
 };
template<class T>
class erchashu
{
public:
    erchashu(int a[],int n);
    void insert(BiNode<T> *root,BiNode<T> *s);
private:
    BiNode<T> *root;
    BiNode<T> *s;
};
template<class T>
void erchashu<T>::insert(BiNode<T> *root,BiNode<T> *s)
{
    if(root==NULL)
        root=s;
    else if(s->data<root->data) insert(root->lchild,s);
          else insert(root->rchild,s);
}
template<class T>
erchashu<T>::erchashu(int a[],int n)
{
    for(int i=0;i<n;i++)
    {
        s=new BiNode<T>;s->data=a[i];
        s->lchild=s->rchild=NULL;
        insert(root,s);
    }
}
void main()
{
    int we[]={53,12,26,56,89,15,42,36};
    erchashu<int> b(we,8);
   
}
一切都正常,只在最后一步运行出不能读,什么原因
搜索更多相关主题的帖子: 运行 
2009-09-07 17:19
serious
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:81
专家分:497
注 册:2009-8-18
收藏
得分:10 
原因是"root"的内容不是"NULL" :
程序代码:
template<class T>
erchashu<T>::erchashu(int a[],int n)
{
    root = NULL; //这里"root"的初始化
    for(int i=0;i<n;i++)
    {
        s=new BiNode<T>;s->data=a[i];
        s->lchild=s->rchild=NULL;
        insert(root,s);
    }
}
2009-09-08 05:35
wxjeacen
Rank: 7Rank: 7Rank: 7
等 级:禁止访问
帖 子:1291
专家分:628
注 册:2009-3-22
收藏
得分:10 
程序代码:
#include<iostream>                          
using namespace std;                        

template<class T>
struct BiNode 
{             
    T data;   
    BiNode<T> *lchild,*rchild;
};                         
template<class T>
class BiTree
{
public:
    BiTree(int a[],int n);
    void insert(BiNode<T> *root,BiNode<T> *s);
private:
    BiNode<T> *root;
    BiNode<T> *s;
};
template<class T>
void BiTree<T>::insert(BiNode<T> *root,BiNode<T> *s)
{
    if(root==NULL)
        root=s;
    else if(s->data<root->data) insert(root->lchild,s);
    else insert(root->rchild,s);
}
template<class T>
BiTree<T>::BiTree(int a[],int n):root(NULL)
{
    for(int i=0;i<n;i++)
    {
        s=new BiNode<T>;
        s->data=a[i];
        s->lchild=s->rchild=NULL;
        insert(root,s);
    }
}
int main()
{
    int we[]={53,12,26,56,89,15,42,36};
    BiTree<int> b(we,8);
    return 0;
}

生命不熄,战斗不止.
2009-09-08 14:41
快速回复:一切都正常,只在最后一步运行出不能读
数据加载中...
 
   



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

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