#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
const int a[] = { 4, 1, 0, 0, 7, 0, 0 };
int index = 0;
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
void CreatTree(TreeNode** T)
{
int value;
//cout << "please input the value\n";
//cin >> value;
value = a[index++];
if (value == 0)
*T = NULL;
else
{
*T = new TreeNode(value);
CreatTree(&(*T)->left);
CreatTree(&(*T)->right);
}
};
void Inorder(TreeNode *root, vector<int>&v, int &small, int &big){
//中序遍历获得最小的叶节点和最大的叶节点的索引
if (!root)
return;
Inorder(root->left, v, small, big);
v.push_back(root->val);
if (root->left == NULL&&root->right == NULL){//叶子节点
if (small == -1 || big == -1)
二叉树中最大最小权值节点距离问题
最新推荐文章于 2021-09-03 16:19:40 发布