在代码中描述了如何遍历二叉树的高度,树节点的个数以及遍历二叉树的三种方式:
- 先序遍历:根左右
- 中序遍历:左根右
- 后续遍历:左右根
具体代码如下:
#include <iostream>
#include<string.h>
#include<string>
#include<queue>
using namespace std;
class Node
{
public:
Node():m_left(NULL),m_right() {
}
Node(char v) :m_value(v),m_left(NULL), m_right() {
}
char m_value;
Node* m_left;
Node* m_right;
};
class Tree
{
public:
Tree():m_root(NULL),m_flag('*') {
}
Node