struct Node
{
char data;//数据域
struct Node* LChild;//左子树指针
struct Node* RChild;//右子树指针
};
struct Node* createNode(char data) //创建节点:
{
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
if (newNode == NULL)
{
return NULL;
}
else
{
newNode->data = data;
newNode->LChild = NULL;
newNode->RChild = NULL;
return newNode;
}
}
//写一个插入节点
void insertNode(struct Node* parent, struct Node* LChild, struct Node* RChild)
{
parent->LChild = LChild;
parent->RChild = RChild;
}
void preorder(struct Node* root) //递归函数
{
//先序变量 根左右
if (root != NULL)
{
printf("%c", root->data);//数据根部 输出这里是
preorder(root->LChild);//直接往左子树边走
preorder(root->RChild);//直接往右子树边走
}
}
int main(void)
{
struct Node* A = createNode('A');
struct Node* B = createNode('B');
struct Node* C = createNode('C');
struct Node* D = createNode('D');
struct Node* E = createNode('E');
struct Node* F = createNode('F');
struct Node* G = createNode('G');
//====将上边的data数据连接起来后下边输出 前序写法
insertNode(A, B, C);
insertNode(B, D, E);
insertNode(C, NULL, F);
insertNode(F, G, NULL);
//=============================输出遍历结果
printf("\n前序遍历");
preorder(A); //A是树根
return 0;
前序遍历图:
反汇编中:
请问反汇编中的递归原理
还有能讲解一下C++中左子树和右子树是怎么递归的步骤吗?最好有视频看麻烦了。