总是提示内存非法,不知是什么原因?
typedef struct BinaryTree{
struct BinaryTree *lTree, *rTree;
ElemType date;
}*Tree, SizeofTree;
typedef struct LinkStack{
Tree da;
struct LinkStack *next;
}*Stack, SizeofStack;
Status Preorder(Tree T)
{
Status Push(Stack *, Tree);
Tree Pop(Stack *);
Stack s, p;
Tree Pre = NULL;
int lenStack = 1;
s = (Stack)malloc(sizeof(SizeofStack));
p = s->next;
/*p->da = (Tree)malloc(sizeof(SizeofStack)); */
p->da = T; // 这句总是出错。
printf("%c", T->date);
while(lenStack){
if(T->lTree && T->lTree != Pre){
T = T->lTree;
printf("%c", T->date);
Push(&s, T);
lenStack++;
continue;
}
if(T->rTree && T->rTree != Pre) {
T = T->rTree;
printf("%c", T->date);
Push(&s, T);
lenStack++;
continue;
}
Pre = Pop(&s);
lenStack--;
T = s->next->da;
}
return OK;
}