二叉树赋值操作放在switch函数之后自动循环一次,不放在switch函数内可以正常使用。
Status CreatBiTree(BiTree &T){
printf("xx\n");
TElemType ch;
gets(h);
h++;
if (ch == '*')
T = NULL;
else
{
T = (BiTree)malloc(sizeof(BiTNode));
if (!T)
return ERROR;
T->data = ch;
CreatBiTree(T->lchild);
CreatBiTree(T->rchild);
}
return OK;
}
void menu(){
BiTree T;
TElemType gg;
InitBiTree(T);
printf("n------------------------二叉树操作-----------------------\n");
printf("\n|- -|\n");
printf("\n|- 1-创建 2-销毁 -|\n");
printf("\n|- 4- 先序输出 -|\n");
printf("\n|- 5-中序输出 6-后序输出 -|\n");
printf("\n|- 7-层序输出 8-结点总数 -|\n");
printf("\n|- 9-深度 0-退出 -|\n");
printf("\n|- -|\n");
printf("\n|------------------------------------------------------|\n");
//CreatBiTree(T);
printf("请输入数值进行操作:");
while (scanf_s("%c", &gg)){
if (gg == '0')break;
switch (gg)
{
case '1':
if (InitBiTree(T))
printf("创建成功\n");
//CreatBiTree(T);
break;
case '2':
if (Destory(T))
printf("销毁成功\n");
else
printf("数为空\n"); break;
case '3':
printf("请输入二叉树的值,空用*表示:");
CreatBiTree(T); break;