📄 shude.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct tree
{
char info;
struct tree *left,*right;
};
struct tree *createtree(struct tree *root,struct tree *r,char info)
{
if(!r)
{
r=(struct tree *)malloc(sizeof(struct tree));
if(!r)
{
printf("Out of Memory");
exit(0);
}
r->left=NULL;
r->right=NULL;
r->info=info;
if(!root)return r;
if(info<root->info)root->left=r;
else root->right=r;
return r;
}
if(info<r->info)
createtree(r,r->left,info);
else
createtree(r,r->right,info);
return root;
}
void print_tree(struct tree *r)
{
if(!r)return;
print_tree(r->right);
printf("%c",r->info);
print_tree(r->left);
}
int main(void)
{
char a[10];
root=NULL;
do
{
printf("Enter a letter:");
gets(a);
root=createtree(root,root,*a);
}while(*a);
print_tree(root);
getch();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -