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

  • 相关阅读:
    Git中tag标签的使用
    antd vue Layout 组件收缩展开自定义
    antd vue Popover气泡卡片的使用
    antd vue Tree树形控件的使用
    antd vue Message 全局提示的使用
    tp5.1 关联条件查询haswhere 用field限制字段失效的问题
    Chrome 调试技巧: 调整网速
    html2canvas导出图片模糊
    点击其他区域不让编辑器失去焦点
    启动的项目经常挂怎么办
  • 原文地址:https://www.cnblogs.com/tianyudizhua/p/13485395.html
Copyright © 2011-2022 走看看