0

这是结构,我想将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。我得到的错误是结构节点没有成员“数据”、未声明 val、省略参数名称等。

4

0 回答 0