OMG,我之前没用<queue>,我用递归写的,样例过了就是wa,好气噢,然饿我还不知道哪里错了,下面这个是改良版AC代码;
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <iostream>
using namespace std;
typedef struct node
{
char data;
struct node *L_Kid,*R_Kid;
}Tree;
void initTree(Tree *&T)
{
char str;
cin>>str;
if(str!='#')
{
T=(Tree *)malloc(sizeof(Tree));
T->data=str;
initTree(T->L_Kid);
initTree(T->R_Kid);
}
else T=NULL;
}
void Traverse(Tree *&T)
{
queue<Tree *>q;
q.push(T);
while(!q.empty())
{
Tree *p=q.front();
q.pop();
cout<<p->data;
if(p->L_Kid!=NULL)
q.push(p->L_Kid);
if(p->R_Kid!=NULL)
q.push(p->R_Kid);
}
}
int main()
{
Tree *T;
initTree(T);
Traverse(T);
return 0;
}