#include<string.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char Name[20]; //* 姓名
char NameChar; //* 姓的拼音的首字母
int Age; //* 年龄
char Job[20]; //* 职业
char Friends[50][20]; //* 好友列表
}Person;
typedef struct
{
Person *data;
struct BSTree *lchild;
struct BSTree *rchild;
}BSTree;
void InsertBST(BSTree *T,Person P)
{
BSTree *s = (BSTree *)malloc(sizeof(BSTree));
if(!T)
{
s->lchild = s->rchild =NULL;
s->data->NameChar = P.NameChar;
strcpy(P.Name,s->data->Name);
T = s;
return 1;
}
else if(P.NameChar < s->data->NameChar)
InsertBST(T->lchild,P);
else if(P.NameChar > s->data->NameChar)
InsertBST(T->rchild,P);
}
void CreateBSTree(BSTree *T,int Num,Person *P)
{
T = NULL;
for(int i=0;i<Num;i++)
InsertBST(T,P[i]);
}
BSTree* SearchBST(BSTree *T,char c)
{
if(T==NULL||c==T->data->NameChar )
return T;
else if(c < T->data->NameChar)
SearchBST(T->lchild,c);
else
SearchBST(T->rchild,c);
}
void main()
{
/**初始化社交网络的节点的值**/
printf("请输入该社交网络中的人数:\n");
int Num; //* 社交网络中的人数
int i;
scanf("%d",&Num);
Person Pinfo[Num];
for(i=0;i<Num;i++)
{
printf("请输入第%d个人的名字:\n",i+1);
scanf("%s",Pinfo[i].Name);
getchar();
printf("请输入%s的姓氏的拼音的首字母(小写):\n",Pinfo[i].Name);
scanf("%c",&Pinfo[i].NameChar);
printf("请输入%s的年龄:\n",Pinfo[i].Name);
scanf("%d",&Pinfo[i].Age);
printf("请输入%s的职业:\n",Pinfo[i].Name);
scanf("%s",Pinfo[i].Job);
getchar();
}
BSTree *T = malloc(sizeof(BSTree)*1);
CreateBSTree(T,Num,Pinfo); //* 构建一棵二叉排序数
/**查找二叉树**/
char c;
BSTree *t;
printf("请输入你要查找的对象的姓氏的首字母(小写)");
scanf("%c",c);
t = SearchBST(T,c);
if(t)
printf("查找成功,结果为%\n",t->data->Name);
else
printf("查找失败\n");
system("pause");
}
就标黄的那一句是为什么啊。(应该是错那里了)