zoukankan      html  css  js  c++  java
  • 队列未知错误

    #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;
    }

  • 相关阅读:
    cnblog项目--20190309
    django js引入失效问题
    Python老男孩 day16 函数(六) 匿名函数
    Python老男孩 day16 函数(五) 函数的作用域
    Python老男孩 day15 函数(四) 递归
    Python老男孩 day15 函数(三) 前向引用之'函数即变量'
    Python老男孩 day15 函数(二) 局部变量与全局变量
    Python老男孩 day14 函数(一)
    Python老男孩 day14 字符串格式化
    Python老男孩 day14 集合
  • 原文地址:https://www.cnblogs.com/tianyudizhua/p/13485395.html
Copyright © 2011-2022 走看看