主题:树的问题
这是我写的代码,但是不知道那里出错了,我找了好久,还是没有找到。望各位高手指点一下。谢谢了....
[code=c]
#include <iostream.h>
struct node
{
int data;
node *lchild,*rchild;
};
void CreateBiTree()
{ node *root;
for(int i=0;i<8;i++)
{
switch(i)
{
case 0:
root=new node ;
root->data=1;
root->lchild=NULL;
root->rchild=NULL;
case 1:
root->lchild=new node ;
root->lchild->data=2;
root->lchild->lchild=NULL;
root->lchild->rchild=NULL;
case 2:
root->rchild=new node;
root->rchild->data=3;
root->rchild->lchild=NULL;
root->rchild->rchild=NULL;
case 3:
root->lchild->lchild=new node;
root->lchild->lchild->data=4;
root->lchild->lchild->lchild=NULL;
root->lchild->lchild->rchild=NULL;
case 4:
root->lchild->rchild=new node;
root->lchild->rchild->data=5;
root->lchild->rchild->lchild=NULL;
root->lchild->rchild->rchild=NULL;
case 5:
root->rchild->lchild->data=6;
root->rchild->lchild->lchild=NULL;
root->rchild->lchild->rchild=NULL;
case 6:
root->lchild->rchild->lchild=new node;
root->lchild->rchild->lchild->data=7;
root->lchild->rchild->lchild->lchild=NULL;
root->lchild->rchild->lchild->rchild=NULL;
case 7:
root->lchild->rchild->rchild=new node;
root->lchild->rchild->rchild->data=8;
root->lchild->rchild->rchild->lchild=NULL;
root->lchild->rchild->rchild->rchild=NULL;
}
}
}
void main()
{
CreateBiTree();
}
[/code]