主题:二叉树不会啊
蛋蛋001
[专家分:0] 发布于 2007-10-25 19:17:00
今天讲二叉树,迷迷糊糊的。有没有应用的程序,借来看看。增长下见识。谢拉~~
回复列表 (共4个回复)
沙发
wzz_61 [专家分:30] 发布于 2007-10-26 20:28:00
二叉树挺简单的啊,它和前几章都没什么联系,只要你上课好好听就可以 听懂的啊,要不你就从百度中搜索视频教程,看看吧应该有很大帮助的
板凳
ripya [专家分:90] 发布于 2007-10-27 00:25:00
我编了个 只有建立和先序遍历的,
#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 楼
蛋蛋001 [专家分:0] 发布于 2007-10-28 16:51:00
谢了……
4 楼
ripya [专家分:90] 发布于 2007-10-30 23:44:00
[quote]谢了……[/quote]
此帖尚未评分 [em7][em7]
我来回复