看看那里出现了问题
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct ptnode
{
char data;
int parent;
}ptnode;
#define MAX 100
typedef struct ptree
{
ptnode nodes[MAX];
int n; //结点数目
}ptree;
void inittree(ptree &T)
{
for(int i = 0; i < MAX; i++)
{
T.nodes[i].data = '#';
T.nodes[i].parent = -1;
}
T.n = 0;
}
void creattree(ptree &T) //用双亲表示法建立一颗树
{
int e;
char node;
printf("请输入树的结点个数:");
scanf("%d", &T.n);
printf("请输入%d个树的结点数据:", T.n);
for(int i = 0; i < T.n; i++)
{
scanf("%c ", &node);
if(node != '#')
{
T.nodes[i].data = node;
}
else continue;
}
printf("请输入结点双亲的的位置:");
for(int j = 0; j < T.n; j++)
{
scanf("%d ", &e);
if(e != -1)
{
T.nodes[j].parent = e;
}
}
}
void preorder(ptree &T, int i)
{
for(int j = 0; j < T.n; j++)
{
if(T.nodes[j].parent == i)
{
printf("%c", T.nodes[j].data);
preorder(T, j);
}
}
}
int main(void)
{
ptree T;
inittree(T);
creattree(T);
printf("先序遍历树:");
preorder(T, -1);
return 0;
}