二叉树结点一直为NULL怎么回事呢

关于二叉树建立结点为空


为什么T结点一直为NULL呢?
是我电脑的问题吗?
我一直分析不出来。求大神路过的看看

#include
#include

typedef struct BiTNode {
	int data;
	struct BiTNode* lchild, * rchild;
}BiTNode,*BiTree;//二叉树结构

void insertNode(BiTNode* treePtr, int value)//插入节点
{

	/* if treePtr is NULL */
	if (treePtr == NULL) {

		treePtr = (BiTNode *)malloc(sizeof(BiTNode));

		if (treePtr != NULL) {
			(treePtr)->data = value;
			(treePtr)->lchild = NULL;
			(treePtr)->rchild = NULL;
		}
		else {
			printf("%d not inserted. No memory available.\n", value);
		}

	}
	else {

		/* insert node in left subtree */
		if (value < (treePtr)->data) {
			insertNode(((treePtr)->lchild), value);
		}
		else {

			/* insert node in right subtree */
			if (value > treePtr->data) {
				insertNode(((treePtr)->rchild), value);
			}
			else {
				printf("dup");
			}
		}

	}

}

int main(void) {

	BiTree T = NULL;//定义一根空树

	insertNode(T, 22);
	insertNode(T, 2);
	insertNode(T, 16);

	printf("%d", T->data);

	return 0;
}

你可能感兴趣的:(新手提问)