队列未知错误

#include<cstdio>
#include<iostream>
#include<stdlib.h>
#include<queue>
using namespace std;
typedef struct BTree{
    int data;
    BTree *lchild;
    BTree *rchild;
    
}BiTree;
int num=0;
int A[30];//后序
int B[30];//中序
int N;
queue<int> res;
void levelorder(BiTree * root)
{
    if(root==NULL)return;
    BiTree* temp;
    queue<BiTree*> q;
    q.push(root);
    while(!q.empty())
    {
        temp=q.front();
        res.push(temp->data);
        q.pop();
       // printf("%d",temp->data);
        //num++;
       // if(num<N)printf(" ");
        if(temp->lchild)
        {
            q.push(temp->lchild);
        }
        if(temp->rchild)
        {
            q.push(temp->rchild);
        }
    }
}
BiTree* create(int postL,int postR,int inL,int inR)
{
    if(postL>postR)return NULL;
    BiTree * root=(BiTree*)malloc(sizeof(BiTree));
    root->lchild=NULL;
    root->lchild=NULL;
    root->data=A[postR];
    int i;
    for(i=inL;B[i]!=root->data;i++);
    int leftLen=i-inL;
    int rightLen=inR-i;
    if(leftLen)
    {
        root->lchild=create(postL,postL+leftLen-1,inL,inL+leftLen-1);
    }else
    {
        root->lchild=NULL;
    }
    if(rightLen)
    {
        root->rchild=create(postR-rightLen,postR-1,inR-rightLen+1,inR);
    }else
    {
        root->rchild==NULL;
    }
    return root;
}
int main()
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&A[i]);
    for(int i=0;i<N;i++)
        scanf("%d",&B[i]);
    BiTree* root=create(0,N-1,0,N-1);
    levelorder(root);
    cout<<res.empty();
//    for(int i=0;i<res.size()-1;i++)
//    {
//        int data=res.front();
//        res.pop();
//        printf("%d ",data);
//    }
//    printf("%d",res.front());
    return 0;
}

原文地址:https://www.cnblogs.com/tianyudizhua/p/13485395.html