

BinaryTreeNode.cpp
/*设二叉树以二叉链表方式存储,试编写求解下列问题的递归算法。
设二叉树结点和二叉树结构体定义如下:
(1)求一棵二叉树的高度;
(2)求一棵二叉树中的结点个数;
(3)交换一棵二叉树中每个结点的左、右子树。*/
#include<iostream>
#include<cstring>
#include <stdio.h>
#include<stdlib.h>
#include "Queue.h"
#include <math.h>
#include "BinaryTreeNode.h"
using namespace std;
BinaryTreeNode* PreCreateBt(BinaryTreeNode *&t) //先序创建二叉树
{
char ch;
ch = getchar();
fflush(stdin);
if (ch == '#'){
t = NULL;
}
else
{
t = (BinaryTreeNode *)malloc(sizeof(BinaryTreeNode));
t->Data = ch;
printf("left Child:\n");
t->lChild = PreCreateBt(t->lChild);
printf("right Child:\n");
t->rChild = PreCreateBt(t->rChild);
}
return t;
}
int Height(BinaryTreeNode *t){
if(t == NULL){
return 0;
}
if(t->lChild == NULL && t->rChild == NULL){
return 1;
}
return max(Height(t->lChild),Height(t->rChild)) + 1;
}
void Swap(BinaryTreeNode *t){
if(t == NULL)
return;
else{
BinaryTreeNode *temp = t->lChild;
t->lChild = t->rChild;
t-