我来我网
https://5come5.cn
 
您尚未 登录  注册 | 菠菜 | 软件站 | 音乐站 | 邮箱1 | 邮箱2 | 风格选择 | 更多 » 
 

axiuluo



性别: 帅哥 状态: 该用户目前不在线
等级: 栋梁之材
家族: 单身贵族
发贴: 568
威望: 0
浮云: 1164
在线等级:
注册时间: 2006-10-06
最后登陆: 2008-06-29

5come5帮你背单词 [ athlete /'æθli:t/ n. 运动员 ]


编程

新编了一段程序。二叉树中序遍历。但就一个错误,怎么也不行。求助达三大四师兄帮忙啊
Copy code
#include<stdlib.h>
#include<stdio.h>

struct tree
{struct tree*left;
int data;
struct tree*right;

};
typedef struct tree treenode;
typedef treenode *b_tree


b_tree insert_node(b_tree root,int node)
{
b_tree nnode;
b_tree cnode;
b_tree pnode;
nnode=(b_tree)malloc(sizeof(treenode));
nnode->node=node;
nnode->right=NULL;
nnode->left=NULL;

if(root==NULL)
return nnode;
else
{
cnode=root;
while(cnode!=NULL)
{
  pnode=cnode;
  if(cnode->data>node)
  cnode=cnode->left;
  else
  cnode=cnode->right;
}
if(pnode->data>node)
pnode->left=nnode;
else
pnode->right=nnode;
}
return root;
}

b_tree create_btree(int*data,int len)
{
b_tree root=NULL;
int i;
for(i=0;i<len;i++)
root=insert_node(root,data[i]);
return root;
}

void inorder(b_tree point)
{
if(point!=NULL)
{
inorder(point->left);
printf("%d",point->data);
inorder(point->right);
}

}

void main()
{
b_tree root=NULL;
inti,j;
int value;
int nodelist[20];
printf("\n please input the letter(exit for 0):\n");
j=0;
scanf("%d",&value);
while(j!=0)
{
nodelist[j]=value;
j=j+1;
scanf("%d",&value);

}

root=create_btree(nodelist,j);
printf("\n the ordertrv result is:\n");
inorder(root);
printf("\n")
}



[ 此贴被kangtalc在2006-12-12 21:57重新编辑 ]
顶端 Posted: 2006-12-12 17:59 | [楼 主]
kangtalc



性别: 帅哥 状态: 该用户目前不在线
头衔: 揍敌客·奇犽
等级: 希望之光
家族: 万人坑恋影部落
发贴: 1723
威望: 5
浮云: 1113
在线等级:
注册时间: 2005-09-21
最后登陆: 2008-06-29

5come5帮你背单词 [ an /æn, ən/ art. 一(个);每一(个);(同类事物中的)任何一个 ]


nnode=(b_tree)malloc(sizeof(treenode));
nnode->node=node;
nnode->right=NULL;
nnode->left=NULL;

那个node应该是data
顶端 Posted: 2006-12-12 18:09 | [1 楼]
axiuluo



性别: 帅哥 状态: 该用户目前不在线
等级: 栋梁之材
家族: 单身贵族
发贴: 568
威望: 0
浮云: 1164
在线等级:
注册时间: 2006-10-06
最后登陆: 2008-06-29

5come5帮你背单词 [ tact /tækt/ n. 机智,老练,圆滑 ]


但那里编译没出问题
顶端 Posted: 2006-12-12 18:13 | [2 楼]
axiuluo



性别: 帅哥 状态: 该用户目前不在线
等级: 栋梁之材
家族: 单身贵族
发贴: 568
威望: 0
浮云: 1164
在线等级:
注册时间: 2006-10-06
最后登陆: 2008-06-29

5come5帮你背单词 [ revolt /ri'vəult/ v. 起义,造反,厌恶,反感;n. 反抗,造反 ]


b_tree insert_node(b_tree root,int node)
说这句有问题。
是不是结构体的问题啊
顶端 Posted: 2006-12-12 18:15 | [3 楼]
kangtalc



性别: 帅哥 状态: 该用户目前不在线
头衔: 揍敌客·奇犽
等级: 希望之光
家族: 万人坑恋影部落
发贴: 1723
威望: 5
浮云: 1113
在线等级:
注册时间: 2005-09-21
最后登陆: 2008-06-29

5come5帮你背单词 [ tag /tæg/ n. 标签,标牌 ]


我帮你调试调试
顶端 Posted: 2006-12-12 21:58 | [4 楼]
kangtalc



性别: 帅哥 状态: 该用户目前不在线
头衔: 揍敌客·奇犽
等级: 希望之光
家族: 万人坑恋影部落
发贴: 1723
威望: 5
浮云: 1113
在线等级:
注册时间: 2005-09-21
最后登陆: 2008-06-29

5come5帮你背单词 [ tariff /'tærif/ n. 关税,税奉,(旅馆、饭店等)价目表,收费表 ]


typedef struct tree treenode;
typedef treenode *b_tree;

上面这个分号没加...
顶端 Posted: 2006-12-12 22:27 | [5 楼]
我来我网·5come5 Forum » 程序员之家

Total 0.014947(s) query 5, Time now is:10-28 03:32, Gzip enabled
Powered by PHPWind v5.3, Localized by 5come5 Tech Team, 黔ICP备16009856号