- 根据用户输入的扩展的先序遍历序列创建二叉树的二叉链表存储结构
- 编写二叉树的先序遍历、后序遍历、中序遍历算法
- 编写函数,求二叉树高度
- 编写函数,求二叉树中叶子节点的个数。
- (选做)写一个函数LeftChild(T,e)或RightChild(T,e),实现求二叉树T中某个非叶子结点e的左孩子或右孩子,若e无左孩子或右孩,则返回空;
- (选做)写一个函数Parent(T,e),实现求二叉树T中某个非根结点e的双亲,若e无双亲,则返回空
代码实现 :
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef struct BinNode {//初始化
char element;
struct BinNode* left;
struct BinNode* right;
}BinNode, * BinTree;
void CreateBinTree(BinTree* tree)
{//根据所有序列创建二叉树
char ch;
scanf_s("%c", &ch);
if (ch == '*') {