28 #include"LinkQueue-operations.h"
29
30 Status CreateTree(CSTree &T)
31 { //根据孩子兄弟法建立树T。 32
33 char c[20]; //临时存放孩子结点(设不超过20个)的值。 34
35 CSTree p,p1;
36 LinkQueue q;
37 int i,l;
38 InitQueue(q);
39 printf("请输入根结点(字符型,空格为空):"); 40
41 scanf("%c%*c",&c[0]); //%*c用来接收回车符。 42
43 if(c[0]!=Nil) // 构造的树不空。 44
45 {
46 T=(CSTree)malloc(sizeof(CSNode));
47 T->data=c[0];
48 T->nextsibling=NULL; //建根结点。 49
50 EnQueue(q,T);
51 while(!QueueEmpty(q)) //队列中不空,未建立完毕。 52
53 {
54 DeQueue(q,p); //队中结点出队。 55
56 printf("请按长幼顺序输入结点%c的所有孩子:57
58 ",p->data);
59 gets(c);
60 l=strlen(c); //当前结点的孩子树为l。 61
62 if(l>0)
63 {//有孩子。 64
65
66 p1=p->firstchild=(CSTree)malloc(sizeof(CSNode)); 67 p1->data=c[0]; //为长子赋值。 68
69 for(i=1;i<l;i++)
70 { //创建其它孩子的结点并赋值。 71