此程序有什么问题?帮忙修改下
#include<stdio.h>
struct tree {
char info;
struct tree *left,*right;
};
struct tree *create_btree(struct tree *root,struct tree *r,char info);
struct tree *search_btree(struct tree *root,char key);
void main()
{
char s[100], c ;
struct tree *root=0, *p;
printf("Input a letter for Creating the Binary_Tre(Directly press <Enter> to stop ):\n");
do{
printf("Input a letter: ");
gets(s);
if (!root)
root=create_btree(root,root,*s);
else
create_btree(root,root,*s);
}while (*s) ;
while ( c!='!')
{
print_btree(root,0);
printf("Enter a character to find( '!' to stop ):");
scanf("%s",&c);
printf("\n");
p=search_btree(root,c);
printf("\n");
}
}
struct tree *create_btree(struct tree *root,struct tree *r,char info)
{
if (r ==0 )
{
r=new(struct tree);
if(r==0)
{
printf("Out of memory\n");
return 0 ;
}
r->left=0;
r->right=0;
r->info=info;
if(root)
{
if(info<root->info)
root -> left=r;
else
root->right=r;
}
else
{
r->right=0;
r->left = 0;
}
return r;
}
if(info<r->info)
create_btree(r,r->left,info);
if(info>=r->info)
create_btree(r,r->right,info);
}
struct tree *search_btree(struct tree *p,char key)
{
struct tree *root;
root=p;
if (!root)
{
printf("Empty btree\n");
return root;
}
while(root->info!=key)
{
if(key<root->info)
root=root->left;
else
root=root->right;
if(root==0)
{
printf("Search Failure\n");
return 0;
}
}
if (root !=0)
printf("Successful search\n key=%c\n",root->info);
return root ;
}
编程高手指教
答案:1 悬赏:50 手机版
解决时间 2021-06-02 10:03
- 提问者网友:愿为果
- 2021-06-02 05:20
最佳答案
- 五星知识达人网友:鱼芗
- 2021-06-02 05:56
搞2叉树么。。你又不说运行结果跟预期的哪里不同,怎么看啊。。。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯