一个队列,一个标志
#include<queue>
using namespace std;
int countdepthNR(BinaryTreeNode * ptr)
{
int x=0;
queue<BinaryTreeNode *>Queue;
BinaryTreeNode * mark = new BinaryTreeNode(-255);
BinaryTreeNode * buf;
Queue.push(ptr);
Queue.push(mark);
BinaryTreeNode * temp;
while(!Queue.empty())
{
temp=Queue.front();
if(temp==mark)
{
++x;
}
else
{
if(temp->left)
Queue.push(temp->left);
if(temp->right)
Queue.push(temp->right);
if(temp->left||temp->right)Queue.push(mark);
}
Queue.pop();
}
return x;
}