以下是结构,我想将organT插入树中。
typedef struct {
int month;
int day;
int year;
} dateT;
typedef struct {
int hour;
int minute;
} timeT;
typedef struct {
char name[SIZE];
char organname[SIZE];
char bloodtype[BLOODTYPESIZE];
dateT dateAdded;
timeT timeAdded;
} organT;
struct node{
struct data;
struct node* left;
struct node* right;
};
struct node* insert(struct node *root, struct node *element);
struct node* create_node(struct val);
这是插入和节点初始化代码:
struct node* insert(struct node *root, struct node *element) {
// Inserting into an empty tree.
if (root == NULL)
return element;
else {
// element should be inserted to the right.
if (element->data > root->data) {
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else {
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
// creating a new node
struct node* create_node(struct val) {
struct node* temp;
temp = (struct node*)malloc(sizeof(struct val));
temp->data = val;
temp->left = NULL;
temp->right = NULL;
return temp;
}
我想将多个结构插入到二叉树中。我想进入的结构是organT。我仍然是C语言的初学者,所以我的代码中可能会有一些非常明显的错误,所以对我来说是非常明显的!我得到的错误是结构节点没有成员'数据',val未声明,参数名称省略等。无论如何任何帮助将不胜感激!