把作业发上来,求拍砖……
这个是我写的二叉树,有哪里写得不好的还望指正。我想问一下,出了这种写法,其他的写法是怎么写的?
书上的有点看不懂……
今天晚上我再写树的遍历
(*^__^*) 嘻嘻……
程序代码:/*程序:二叉树……
作者:thlgood(webmaster @ )
版本:v0.1
*/
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
struct tree
{
struct tree *left;
char str[SIZE];
struct tree *right;
};
typedef struct tree tree;
tree *Creat(tree *p, int x);
int main()
{
tree *head;
int i = 0;
head = Creat (head, i);
return 0;
}
tree *Creat(tree *p, int x)
{
p = (tree *)malloc(sizeof(tree));
if(x == 4)
{
printf("请输入一个字符串:\n");
scanf("%s", p->str);
p->left = NULL;
p->right = NULL;
}
else
{
++x;
printf("请输入一个字符串:\n");
scanf("%s", p->str);
p->left=Creat(p->left, x);
p->right=Creat(p->right, x);
}
return p;
}








