编程高手请进~~~帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/09/24 10:39:39
建立一棵二叉树,按某种次序输出二叉树中的结点。
在上面建立的二叉树中计算结点的个数。
~我很笨~~告诉我怎么运行吧~我输什么进去都是Press any key to continue~

#include <stdio.h>

typedef struct _treenode
{
int data;
struct _treenode *lchild;
struct _treenode *rchild;
} treenode;

treenode *create(treenode *root,int n)
{
treenode *p;

if(root==NULL)
{
p=(treenode*)malloc(sizeof(treenode;));
p->data=n;
return p;
}
else if(root->data < n)
{
create(root->rchild,n);
}
else
{
create(root->lchild,n);
}
}

int count(treenode *root)
{
if(root==NULL)
{
return 0;
}
else
{
return 1+count(root->lchild)+count(root->rchild);
}
}

main()
{
treenode *root;
int n;

scanf("%d",&n);
while(n!=0)
{
root=create(root,n);
scanf("%d",&n);
}
printf("node count=%d",count(root));
//destroy tree
}

试试下面的程序吧,请加分
#include "stdio.h&quo