#include<stdio.h> #include<stdlib.h> typedef struct BiTNode{ char data; struct BiTNode *lchild; struct BiTNode *rchild; }BiTNode,*Bintree; void CreateBinaryTree(Bintree *T){ char ch; scanf("%c",&ch); if(ch=='#') *T==NULL; else{ *T = (Bintree)malloc(sizeof(BiTNode)); (*T)->data = ch; CreateBinaryTree(&(*T)->lchild); CreateBinaryTree(&(*T)->rchild); } } void midOrder(Bintree T){ if(T){ midOrder(T->lchild); printf("%c",T->data); midOrder(T->rchild); } } int main() { Bintree T; CreateBinaryTree(&T); midOrder(T); return 0; }修改这段代码
时间: 2023-06-18 13:07:32 浏览: 204
#include <stdio.h>
代码中存在一个明显的错误,即第11行应该是赋值操作而不是等于操作。此外,函数名`midOrder`应该改为`inOrder`,以符合中序遍历的命名规范。修改后的代码如下:
```c
#include <stdio.h>
#include <stdlib.h>
typedef struct BiTNode{
char data;
struct BiTNode *lchild;
struct BiTNode *rchild;
} BiTNode, *Bintree;
void CreateBinaryTree(Bintree *T){
char ch;
scanf("%c", &ch);
if (ch == '#')
*T = NULL;
else{
*T = (Bintree)malloc(sizeof(BiTNode));
(*T)->data = ch;
CreateBinaryTree(&((*T)->lchild));
CreateBinaryTree(&((*T)->rchild));
}
}
void inOrder(Bintree T){
if (T){
inOrder(T->lchild);
printf("%c", T->data);
inOrder(T->rchild);
}
}
int main(){
Bintree T;
CreateBinaryTree(&T);
inOrder(T);
return 0;
}
```
阅读全文