2022.1.28 练习 PAT甲 1099 Build A Binary Search Tree (原题链接)

题解如下:

#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE=110;
int n;
int indexx=0;
int num[MAX_SIZE];struct node
{int data;int lchild;int rchild;
}Node[MAX_SIZE];void inorder(int root)
{if(root==-1)return;inorder(Node[root].lchild);Node[root].data=num[indexx++];inorder(Node[root].rchild);
}void layerorder(int root)
{queue<int>q;q.push(root);int num=0;while(!q.empty()){int now=q.front();q.pop();cout<<Node[now].data;num++;if(num<n)cout<<" ";if(Node[now].lchild!=-1)q.push(Node[now].lchild);if(Node[now].rchild!=-1)q.push(Node[now].rchild);}
}
int main()
{std::ios::sync_with_stdio(false);cin>>n;for(int i=0;i<n;i++){int l,r;cin>>l>>r;Node[i].lchild=l;Node[i].rchild=r;}for(int i=0;i<n;i++){cin>>num[i];}sort(num,num+n);inorder(0);layerorder(0);return 0;
}

PAT 甲 1099 Build A Binary Search Tree相关推荐

  1. PAT甲级1099 Build A Binary Search Tree (30分):[C++题解]建立二叉搜索树、dfs和bfs

    文章目录 题目分析 题目链接 题目分析 题意重述:给定一棵二叉树的结构,和待填的数值,请将数据填到二叉树中的结点中,使之满足二叉搜索树的性质. 然后按照层序遍历输出数值. 分析: 本题分两步. 第一步 ...

  2. PAT甲级——1099 Build A Binary Search Tree (二叉搜索树)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90701125 1099 Build A Binary Searc ...

  3. 1099. Build A Binary Search Tree (30)

    1099. Build A Binary Search Tree (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  4. C++学习之路 | PTA(甲级)—— 1099 Build A Binary Search Tree (30分)(带注释)(精简)

    1099 Build A Binary Search Tree (30分) A Binary Search Tree (BST) is recursively defined as a binary ...

  5. 【PAT】A1099. Build A Binary Search Tree (30)

    Author: CHEN, Yue Organization: 浙江大学 Time Limit: 200 ms Memory Limit: 64 MB Code Size Limit: 16 KB A ...

  6. 【PAT (Advanced Level) Practice】1099 Build A Binary Search Tree (30 分)

    深搜+广搜 #include <iostream> #include <stack> #include <queue> #include <vector> ...

  7. 【PAT甲级】1099 Build A Binary Search Tree (30 分)

    一.题目分析 1. 翻译 recursively:递归地 property:性质 2. 关键点 1)二叉排序树的中序遍历结果是递增排序的,因此直接中序遍历题目给出的二叉树,将排好序的数据填入后,层序遍 ...

  8. PAT 1099 Build A Binary Search Tree

    Sample Input: 9 1 6 2 3 -1 -1 -1 4 5 -1 -1 -1 7 -1 -1 8 -1 -1 73 45 11 58 82 25 67 38 42 Sample Outp ...

  9. 1099 Build A Binary Search Tree

    1. 本题给出了树的样子,给出了用来填充的数列,并且告诉是一棵二叉查找树. 2. 先用静态存储的方式将树的框架建立起.然后对数列进行小到大排序,利用BST中序遍历是升序的性质,通过中序遍历将数值填充的 ...

最新文章

  1. Freemarker详细解释
  2. 在使用import语句时
  3. linux shell printf 格式化输出 数字 字符串
  4. 基于weblogic 的EJB 学习笔记-JSP教程,资料/其它
  5. gulp中使用babel-polyfill编译es6拓展语法
  6. 盘点阿里程序员常用的 15 款开发者工具
  7. oracle之单行函数之子查询之课后练习
  8. CVPR 2020 论文大盘点—目标跟踪篇
  9. 无法下载php怎办,php无法下载大文件怎么办
  10. 微众银行互联网架构首次曝光
  11. Linux网络服务参数配置说明及实战
  12. 汽车主要电子控制系统模块
  13. 2022茶艺师(中级)考试题及模拟考试
  14. 参加2010年磨房《在路上 - 十年》百公里徒步活动小记
  15. 独孤求败-小滴云架构大课十八式-xdclass2022
  16. java 中文星期表示_java之获得中文星期几
  17. 11对战平台服务器维护,11对战平台无法进入游戏【解决方法】
  18. 实验三:基于A*算法的迷宫
  19. http://strong0511.blog.163.com/blog/static/15115379520124510362211/
  20. 一语中的丨高对抗重实战攻防视角下,企业安全运营到底该怎么做?

热门文章

  1. oracle取每日固定时间,Oracle查询每天固定时间段的数据
  2. Cinemachine(二)制作不会穿墙(会避开障碍物)的摄像头(Cinemachine Collider)
  3. 如何按照nodejs
  4. Xcode使用教程详细讲解 1
  5. 初识C语言 —— 数组(一)
  6. 基于单片机智能衣柜 智能衣橱 换气除湿制系统紫外线消毒的设计与实现
  7. Field xxxMapper in com.xxx.service.UserService required a bean of type ....
  8. 两个求和符号,Matlab写法
  9. 【python爬虫】爬取ajax数据-马蜂窝旅游网
  10. VC组合框ComboBox控件用法