二叉树的建立与遍历(C语言实现)- 练习
标签:targe get list include size ++ http lib add
ref
#include
#include
typedef struct node {
int data;
struct node *lchild, *rchild;
}bitree_t;
bitree_t *createNode(int data) {
bitree_t *p = (bitree_t *)malloc(sizeof(bitree_t));
p->data = data;
p->lchild = p->rchild = NULL;
return p;
}
bitree_t *addNode(int value, bitree_t *pNode) {
if (pNode == NULL)
return createNode(value);
if (value == pNode->data)
return pNode;
if (value data) {
if (pNode->lchild == NULL) {
pNode->lchild = createNode(value);
return pNode->lchild;
} else {
addNode(value, pNode->lchild);
}
} else {
if (pNode->rchild == NULL) {
pNode->rchild = createNode(value);
return pNode->rchild;
} else {
addNode(value, pNode->rchild);
}
}
return pNode;
}
void listNode(bitree_t *pNode) {
if (pNode != NULL) {
printf("%d\n", pNode->data);
listNode(pNode->lchild);
listNode(pNode->rchild);
}
}
int main(void) {
bitree_t *pRoot = NULL;
pRoot = createNode(0);
int rawdata[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int i;
for (i = 0; i
二叉树的建立与遍历(C语言实现)- 练习
标签:targe get list include size ++ http lib add
原文地址:https://www.cnblogs.com/muahao/p/14530937.html
评论