#include <deque>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
struct BinaryTreeNode
{
int m_value;
BinaryTreeNode* m_pLeft;
BinaryTreeNode* m_pRight;
}*TPP,TPPP;
void PrintFromToptoBottom(BinaryTreeNode* pTreeRoot)
{
if(pTreeRoot == NULL)
return;
BinaryTreeNode *pCurrent;// = pTreeRoot;
deque<BinaryTreeNode*> p;
p.push_back(pTreeRoot);
while(p.size())
{
pCurrent = p.front();
p.pop_front();
cout<<pCurrent->m_value<<" ";
if(pCurrent->m_pLeft)
{
p.push_back(pCurrent->m_pLeft);
}
if(pCurrent->m_pRight)
{
p.push_back(pCurrent->m_pRight);
}
}
}
void CreateBinaryTree(BinaryTreeNode* &T)
{
int value;
cin>>value;
if(value == -1)
return;
else
{
BinaryTreeNode *t;
t=(BinaryTreeNode*)malloc(sizeof(BinaryTreeNode));
t->m_value=value;
t->m_pLeft=NULL;
t->m_pRight=NULL;
T=t;
CreateBinaryTree(T->m_pLeft);
CreateBinaryTree(T->m_pRight);
}
}
void inorder(BinaryTreeNode * &pTree)
{
if(pTree)
{
cout<<pTree->m_value<<" ";
inorder(pTree->m_pLeft);
inorder(pTree->m_pRight);
}
}
int main()
{
BinaryTreeNode *pTree = NULL;
CreateBinaryTree(pTree);
inorder(pTree);
PrintFromToptoBottom(pTree);
}
07-06
07-05
07-06
07-06
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交