#include
#include
#include
#include
#define ElemType int
using namespace std;
typedef struct BiTNode{
ElemType data;
struct BiTNode *lchild,*rchild;
}TNode,*Tree;
int treenum[]={1,2,4,0,0,5,0,0,3,0,0};
int k;
void createTree(Tree &T,int &k)
{
ElemType n;
// printf("输入为0停止!\n");
// scanf("%d",&n);
if(treenum[k]==0){
T=NULL;
k++;
}
else{
T=new TNode;
T->data=treenum[k];
k++;
// cout<<"T="<data<<"k="<lchild,k);
createTree(T->rchild,k);
}
}
void InvertLevel(Tree T){
stack s1;
queue s2;
TNode *temp;
if(T==NULL)
return;
s2.push(T);
while((s2.empty()==false)){
temp=s2.front();
s2.pop();
s1.push(temp->data);
if(T->lchild!=NULL){
InvertLevel(T->lchild);
}
if(T->rchild!=NULL){
InvertLevel(T->rchild);
}
}
while((s1.empty()==false)){
ElemType head;
head=s1.top();
cout<
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)