哪位大侠帮小弟调试一个数据结构程序 谢谢 15
实现二叉树的建立和遍历(二叉链表存储结构)#definemaxsize100#include<stdio.h>typedefstructnode{chardata;str...
实现二叉树的建立和遍历(二叉链表存储结构)
#define maxsize 100
#include<stdio.h>
typedef struct node
{char data;
struct node *lchild,*rchild;
}bitree;
typedef struct
{
bitree *top, *base;
unsigned stacksize;
}sqstack;
bitree createbitree(void);
void preordertraverse(bitree);
int initstack(sqstack *);
int push(sqstack *,bitree);
int main()
{
bitree bt;
printf("please int the root:");
bt=createbitree();
preordertraverse(bt);
printf("\n");
}
char e;
bitree tmp=null;
if((e=getchar())!='#'){
getchar();
tmp=(bitree)malloc(sizeof(bitnode));
if(!tmp)
return null;
tmp->data=e;
printf("please in the liftchild:");
tmp->lchild=createbitree();
printf("please int the rightchild:");
tmp->rchild=createbitree();
}
else
getchar();
return tmp;
}
void preordertraverse(bitree bt)
{
if(bt){
print("%c",bt->data);
}
int nodecount(btree *bt)
{
if(bt=null)
return(0);
else
return(nodecount(bt->left)+nodecount(bt->right)+1);
}
void main()
{
btree *b;
printf("\nthe namecount is:%d",nodecount(b));
} 展开
#define maxsize 100
#include<stdio.h>
typedef struct node
{char data;
struct node *lchild,*rchild;
}bitree;
typedef struct
{
bitree *top, *base;
unsigned stacksize;
}sqstack;
bitree createbitree(void);
void preordertraverse(bitree);
int initstack(sqstack *);
int push(sqstack *,bitree);
int main()
{
bitree bt;
printf("please int the root:");
bt=createbitree();
preordertraverse(bt);
printf("\n");
}
char e;
bitree tmp=null;
if((e=getchar())!='#'){
getchar();
tmp=(bitree)malloc(sizeof(bitnode));
if(!tmp)
return null;
tmp->data=e;
printf("please in the liftchild:");
tmp->lchild=createbitree();
printf("please int the rightchild:");
tmp->rchild=createbitree();
}
else
getchar();
return tmp;
}
void preordertraverse(bitree bt)
{
if(bt){
print("%c",bt->data);
}
int nodecount(btree *bt)
{
if(bt=null)
return(0);
else
return(nodecount(bt->left)+nodecount(bt->right)+1);
}
void main()
{
btree *b;
printf("\nthe namecount is:%d",nodecount(b));
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询