📄 bitree.h
字号:
typedef struct Node
{
DataType data;
struct Node *leftChild;
struct Node *rightChild;
} BiTreeNode;
void BiTreeInitiate(BiTreeNode **root)
{
*root=(BiTreeNode *)malloc(sizeof(BiTreeNode));
(*root)->leftChild = NULL;
(*root)->rightChild = NULL;
}
BiTreeNode *InsertLeftNode(BiTreeNode *curr,DataType x)
{
BiTreeNode *s,*t;
if(curr==NULL)
return NULL;
t=curr->leftChild;
s=(BiTreeNode *)malloc(sizeof(BiTreeNode));
s->data=x;
s->leftChild=t;
s->rightChild=NULL;
curr->leftChild=s;
return curr->leftChild;
}
BiTreeNode *InsertRightNode(BiTreeNode *curr,DataType x)
{
BiTreeNode *s,*t;
if(curr==NULL)
return NULL;
t=curr->rightChild;
s=(BiTreeNode *)malloc(sizeof(BiTreeNode));
s->data=x;
s->rightChild=t;
s->leftChild=NULL;
curr->rightChild=s;
return curr->rightChild;
}
void BiTreeDestroy(BiTreeNode **root)
{
if((*root)->leftChild!=NULL&&(*root)!=NULL)
BiTreeDestroy(&(*root)->leftChild);
if((*root)->rightChild!=NULL&&(*root)!=NULL)
BiTreeDestroy(&(*root)->rightChild);
free(*root);
}
BiTreeNode *DeleteLeftTree(BiTreeNode *curr)
{
if(curr==NULL||curr->leftChild==NULL)
return NULL;
BiTreeDestroy(&curr->leftChild);
curr->leftChild=NULL;
return curr;
}
BiTreeNode *DeleteRightTree(BiTreeNode *curr)
{
if(curr==NULL||curr->rightChild==NULL)
return NULL;
BiTreeDestroy(&curr->rightChild);
curr->rightChild=NULL;
return curr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -