#include <queue>
using namespace std;
int calculateTreeHeight(Node *root)
{
if(root == NULL)
return 0;
int visitedNumber = 0;
int enQueNumber = 1; //当前入栈的序号,root为1
int lastLevelNumber = 1;
int height = 0;
queue<Node*> q;
q.push(root);
while(!q.empty())
{
Node *node = q.front();
q.pop();
visitedNumber++;
if(node->left != NULL)
{
q.push(node->left);
enQueNumber++;
}
if(node->right != NULL)
{
q.push(node->right);
enQueNumber++;
}
//访问到当前level上的最后一个节点
if(visitedNumber == lastLevelNumber)
{
height++;
lastLevelNumber = enQueNumber;
}
}
return height;
}