#include "iostream"
#include "iomanip"
#include "stack"
#include "queue"
using namespace std;
struct BinaryTreeNode{
int data;
BinaryTreeNode *left;
BinaryTreeNode *right;
};
void printFromTopToBottom(BinaryTreeNode *pRoot)
{
if (pRoot == NULL)
return;
queue<BinaryTreeNode*> treeQueue;
treeQueue.push(pRoot);
while (treeQueue.size())
{
BinaryTreeNode *pNode = treeQueue.front();
treeQueue.pop();
cout << setw(4)<<pNode->data;
if (pNode->left)
treeQueue.push(pNode->left);
if (pNode->right)
treeQueue.push(pNode->right);
}
}
int main()
{
system("pause");
return 0;
}
剑指offer面试题23:从上到下打印二叉树
最新推荐文章于 2024-05-21 20:28:34 发布