总是出现该内存不能为“written"??该如何调试呢?
#include <conio.h>#include <stdio.h>
#include <stdlib.h>
#define NULL 0
#define MAX 100
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OVERFLOW 0
#define OK 1
//----树的二叉树(孩子-兄弟)存储表示------
typedef struct CSNode
{
char data;
struct CSNode *firstchild, *nextsibling;
}CSNode, *CSTree;
//----二叉树的二叉链表存储表示------------
typedef struct BiNode
{
char Data;
struct BiNode *lchild, *rchild; //左右孩子指针
}BiNode, *BiTree;
//按先序次序输入二叉树中结点的值(一个字符),空格字符表示空树,
//构造树表表示的二叉树。
int CreateTree(BiNode** pTree) /*Input Example: abd##e##cf##g##*/
{
char ch;
scanf("%c",&ch);
if (ch == '#')
{
( * pTree) = NULL;
}
else
{
if (!(( * pTree) = (BiNode * ) malloc (sizeof(BiNode))))
{
exit(OVERFLOW);
}
(*pTree)->Data = ch;
CreateTree(&(( * pTree)->lchild));
CreateTree(&(( * pTree)->rchild));
}
return 0;
}
//----二叉树转化为森林----------------
int bi_forest(BiNode *t, CSNode *p)
{
if (!t->Data)
{
p->data = NULL;
}
else
{
p->data = t->Data;
bi_forest(t->lchild, p->firstchild); //递归遍历左子树,使其为长子
bi_forest(t->rchild, p->nextsibling); //递归遍历右子树,使其为兄弟
}
return OK;
}
//按凹入表形式打印输出树的元素,i表示结点所在层次,初次调用时i=0
void Print_CSTree(CSNode *T, int i)
{
int j;
CSNode *p = NULL;
for (j = 1; j <= i; j++)
{
printf(" ");
} //留出i个空格以表现出层次
printf("%c\n",T->data); //打印元素,换行
for (p = T->firstchild; p; p = p->nextsibling)
{
Print_CSTree(p, i + 1);
} //打印子树
}
BiNode *T = NULL;
CSNode *p = NULL;
int main()
{
freopen("1.txt","r",stdin);
// T = (CSTree *) malloc (sizeof(CSTree));
CreateTree(&T);
bi_forest(T, p);
Print_CSTree(p, 0);
return 0;
}