编写社交网络的数据结构,要求网络中每个人都有姓名、年龄、职业、好友列表的基本信息。并完成如下编程,用c语言代码实现,不能用第三方库,要求代码完整能运行结果(编不下去了坐等一个dagie,也有可能我的是错的吧也可以打乱重组)
(a)、根据姓的拼音首字母在以26个英文字母顺序所在的位置实现二叉排序树的构建和查找,可以不考虑同拼音的情况。
#include
#include
#include
// 定义社交网络中每个人的信息
typedef struct Person {
char name[20];
int age;
char occupation[20];
struct Person* friends;
} Person;
// 定义二叉排序树的节点
typedef struct BinaryTreeNode {
Person data;
struct BinaryTreeNode* left;
struct BinaryTreeNode* right;
} BinaryTreeNode;
// 定义二叉排序树
typedef struct BinaryTree {
BinaryTreeNode* root;
} BinaryTree;
// 初始化二叉排序树
BinaryTree* initBinaryTree() {
BinaryTree* tree = (BinaryTree*)malloc(sizeof(BinaryTree));
tree->root = NULL;
return tree;
}
// 构建二叉排序树
void insertToBinaryTree(BinaryTree* tree, Person data) {
BinaryTreeNode* newNode = (BinaryTreeNode*)malloc(sizeof(BinaryTreeNode));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
if (tree->root == NULL) {
tree->root = newNode;
return;
}
BinaryTreeNode* current = tree->root;
while (current != NULL) {
if (strcmp(data.name, current