69,369
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
//#define max 100
struct node
{
char data;
int flag;
struct node *left;
struct node *right;
};
struct node *tree = NULL;
void createtree(node *&p) //用指针的引用 或者 指向指针的指针
{
char ch;
ch=getchar();
getchar(); //老妹 你得过滤掉空格
if(ch!='#')
{
p = (struct node*)malloc(sizeof(struct node));
p->data=ch;
p->flag=0;
createtree(p->left);
createtree(p->right);
}
else //输入等于#你得处理吧,指向空
p = NULL;
}
void print(struct node *tree)
{
if(tree!=NULL)
{
printf("%c",tree->data);
print(tree->left);
print(tree->right);
}
}
int main()
{
printf("创建二叉树:");
createtree(tree);
printf("\n");
printf("先序遍历输出:");
print(tree);
printf("\n");
return 0;
} //1 2 3 # # # 4 # #
6.0的编译器丢了吧!
struct node *&p换成 struct node **p
按照如片输入: