回 帖 发 新 帖 刷新版面

主题:二叉树不会啊

今天讲二叉树,迷迷糊糊的。有没有应用的程序,借来看看。增长下见识。谢拉~~

回复列表 (共4个回复)

沙发

二叉树挺简单的啊,它和前几章都没什么联系,只要你上课好好听就可以 听懂的啊,要不你就从百度中搜索视频教程,看看吧应该有很大帮助的

板凳

我编了个  只有建立和先序遍历的,
#include<iostream.h>
#include<string>
#define NULL 0
typedef struct bittree{
    char data;
    bittree *rchild;
    bittree *lchild;
}*Bitree;//creat a bitree struction
int CreatBittree(Bitree &T)//create a bitree preorder
{  
    char ch;
    cin.get(ch);//cin can't read the "space" and so on 
    if(ch==' ')T=NULL;
    else{
        if(!(T=new bittree))exit(1);
        T->data=ch;
        CreatBittree(T->lchild);
        CreatBittree(T->rchild);

    };
    return 1;
}
void Preorder(Bitree &T)
{  if(T==NULL){cout<<"the bitree is empty!\n";exit(1);}
   else{
        cout<< T->data;
        Preorder(T->lchild);
        Preorder(T->rchild);
        };
}
void main()
{    
    Bitree T;
    cout<<"please input the character:\n";
    CreatBittree(T);
    cout<<"output the characters:\n";
    Preorder(T);
    cout<<endl;
}

3 楼

谢了……

4 楼

[quote]谢了……[/quote]
此帖尚未评分 [em7][em7]

我来回复

您尚未登录,请登录后再回复。点此登录或注册