#include "tree.h"
#include <stdlib.h>
Tree *Create_Tree()//创建树
{
Tree* tree = (Tree*)malloc(sizeof(Tree)/sizeof(char));
if (tree == NULL)
{
errno = MALLOC_ERROR;
return NULL;
}
tree->head = (TreeNode*)malloc(sizeof(TreeNode)/sizeof(char));
if (tree->head == NULL)
{
errno = MALLOC_ERROR;
free (tree);
return NULL;
}
tree->head->parent = NULL;
tree->head->childList = NULL;
tree->head->next = NULL;
tree->len = 0;
return tree;
}
int Insert_Tree(Tree *tree, TreeData data, int pos)//增加孩子
{
if (tree == NULL || pos < 0 || pos > tree->len)
{
errno = ERROR;
return FALSE;
}
if (pos != 0 && tree->len == pos)
{
errno = ERROR;
return FALSE;
}
// 新建结点
TreeNode* node = (TreeNode*)malloc(sizeof(TreeNode)/sizeof(char));
if (node == NULL)
{
errno = MALLOC_ERROR;
return FALSE;
}
node->data = data;
node->next = NULL;
// 创建该新节点的孩子结点链表的头节点
node->childList = (ChildNode*)malloc(sizeof(ChildNode)/sizeof(char));
if (node->childList == NULL)
{
errno =