?? 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 + -