#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
using namespace std;
struct BinaryTreeNode{
int val;
BinaryTreeNode* left;
BinaryTreeNode* right;
BinaryTreeNode(int x):val(x),left(NULL),right(NULL){}
};
/// 8
/// / \
/// 6 10
/// / \ / \
/// 5 7 9 11
void sequencePrint(BinaryTreeNode* pRoot);
void tabPrint(BinaryTreeNode* pRoot);
void zhiPrint(BinaryTreeNode* pRoot);
void testBinaryPrint();
///前序顺序打印二叉树
/// 8 6 10 5 7 9 11
void sequencePrint(BinaryTreeNode* pRoot)
{
if(NULL == pRoot)
return;
queue<BinaryTreeNode*> nodes;
nodes.push(pRoot);
while(!nodes.empty())
{
BinaryTreeNode* pNode = nodes.front();
cout<<pNode->val<<" ";
if(NULL != pNode->left)
node
打印二叉树——顺序、分层、之字形
最新推荐文章于 2023-07-27 11:21:05 发布