#include<stdlib.h>
#include<malloc.h>
#include<stdio.h>
#define ok 1;
#define error 0;
typedef struct sun{
char data;
struct sun *lchild;
struct sun *rchild;
}sun,*bittree;
typedef struct zhan{
int *base;
int *top;
int stacksize;
}zhan;
int initstack(zhan &s){
s.base=(int * )malloc(100* sizeof(int));
s.top =s.base;
s.stacksize=100;
return ok;}
int push(zhan &s,int e)
{*(s.top++)=e;
return ok;
}
int pop(zhan &s,int &b)
{ b=*(--s.top);
printf("%d",b);
return ok;
}
stackempty(zhan s){
if(s.top==s.base) {return ok;}
else {return error;}
}
createbittree(bittree &t)
{char ch;
printf("3\n");
scanf("%c",&ch);
if(ch==' ')
t=NULL;
else{
t=(bittree)malloc(sizeof(sun));
t->data=ch;
createbittree(t->lchild);
createbittree(t->rchild);
}
return ok;
}
print(char e)
{printf("%c",e);
return ok;}
int zhongf(bittree t)
{ zhan s;initstack(s);bittree p=t;
while (p||!stackempty(s))
push(s,p);
{if(p){
p=p->lchild;}
else {pop(s,p);
print(p->data);
p=p->rchild;}
}
}
void main(){ bittree t;
createbittree(t);
zhongf(t);
}
为什么无法向栈里压指针呢??