voidpushstack(seqstack* s, bintree* r)//进栈{
s->info[s->top++]= r;}
bintree*popstack(seqstack* s)//出栈{if(s->top)return s->info[--s->top];elsereturnNULL;}void_preprint(bintree* r)//前序遍历输出(非递归){
seqstack* s;
s =(seqstack*)malloc(sizeof(seqstack));
s->top =0;while(r || s->top){if(r){printf("%c",r->info);pushstack(s, r);
r = r->lchild;}else{
r=popstack(s);
r = r->rchild;}}free(s);}void_inprint(bintree* r)//中序遍历输出(非遍历){
seqstack* s;
s =(seqstack*)malloc(sizeof(seqstack));
s->top =0;while(r || s->top){if(r){pushstack(s, r);
r = r->lchild;}else{
r=popstack(s);printf("%c",r->info);
r = r->rchild;}}free(s);}void_postprint(bintree* r)//后序遍历输出(非遍历){
seqstack* s;
s =(seqstack*)malloc(sizeof(seqstack));
s->top =0;while(r || s->top){if(r){
s->info[s->top]= r;
s->tag[s->top++]=0;
r = r->lchild;}else{if(s->tag[s->top -1]==1){
r = s->info[--s->top];printf("%c",r->info);
r =NULL;}else{
r = s->info[s->top -1];
s->tag[s->top -1]=1;
r = r->rchild;}}}free(s);}
递归与非递归计算叶子节点数
voidcountleaves(bintree* r)//计算叶子节点数(递归){if(!r)return;if(!(r->rchild)&&!(r->lchild))count++;countleaves(r->lchild);countleaves(r->rchild);return;}void_countleaves(bintree* r)//计算叶子节点数(非递归){
seqstack* s;
s =(seqstack*)malloc(sizeof(seqstack));
s->top =0;while(r || s->top){if(r){if(!(r->lchild)&&!(r->rchild))count++;pushstack(s, r);
r = r->lchild;}else{
r =popstack(s);
r = r->rchild;}}free(s);}