1099 Build A Binary Search Tree
1099 Build A Binary Search Tree (30)(30 分)

代码:
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
;
struct Node{
int val;
int left,right;
}Tree[N];
int data[N];
int n;
void inOrderTraversal(int root)
{
;
){
inOrderTraversal(Tree[root].left);
Tree[root].val=data[idx++];
inOrderTraversal(Tree[root].right);
}
}
void layerOrderTraversal(int root)
{
;
queue<int> q;
q.push(root);
while(!q.empty()){
int top=q.front();
q.pop();
printf("%d",Tree[top].val);
idx++;
if(idx<n) printf(" ");
) q.push(Tree[top].left);
) q.push(Tree[top].right);
}
}
int main()
{
scanf("%d",&n);
int u,v;
;i<n;i++){
scanf("%d%d",&u,&v);
Tree[i].left=u;
Tree[i].right=v;
}
;i<n;i++)
scanf("%d",&data[i]);
sort(data,data+n);
inOrderTraversal();//中序遍历,填入数据
layerOrderTraversal();
;
}
1099 Build A Binary Search Tree的更多相关文章
- PAT 1099 Build A Binary Search Tree[BST性质]
1099 Build A Binary Search Tree(30 分) A Binary Search Tree (BST) is recursively defined as a binary ...
- PAT甲级——1099 Build A Binary Search Tree (二叉搜索树)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90701125 1099 Build A Binary Searc ...
- pat 甲级 1099. Build A Binary Search Tree (30)
1099. Build A Binary Search Tree (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- PAT (Advanced Level) Practise - 1099. Build A Binary Search Tree (30)
http://www.patest.cn/contests/pat-a-practise/1099 A Binary Search Tree (BST) is recursively defined ...
- 1099. Build A Binary Search Tree (30)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- PAT 甲级 1099 Build A Binary Search Tree
https://pintia.cn/problem-sets/994805342720868352/problems/994805367987355648 A Binary Search Tree ( ...
- PAT 1099. Build A Binary Search Tree (树的中序,层序遍历)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- PAT Advanced 1099 Build A Binary Search Tree (30) [⼆叉查找树BST]
题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following proper ...
- PAT (Advanced Level) 1099. Build A Binary Search Tree (30)
预处理每个节点左子树有多少个点. 然后确定值得时候递归下去就可以了. #include<cstdio> #include<cstring> #include<cmath& ...
随机推荐
- LeetCode第[69]题(Java):Sqrt(x)
题目:求平方根 难度:Easy 题目内容: Compute and return the square root of x, where x is guaranteed to be a non-neg ...
- python递归列出目录及其子目录下所有文件
python递归列出目录及其子目录下所有文件 一.前言 函数的递归,简单来说,就是函数内部调用自己 先举个小例子,求阶乘 def factorial(n): if n == 0: return 1 e ...
- css 中的background:transparent到底是什么意思有什么作用
有时我在看css时,看到有的css属性定义为background:transparent.意思就是背景透明.实际上background默认的颜色就是透明的属性.所以写和不写都是一样的 有段时间没写文章 ...
- Redis 应用笔记
模糊匹配 语法:KEYS pattern 说明:返回与指定模式相匹配的所用的keys. 该命令所支持的匹配模式如下: (1)?:用于匹配单个字符.例如,h?llo可以匹配hello.hallo和hxl ...
- Webpack——解决疑惑,让你明白
Webpack——解决疑惑,让你明白 极客教程 作者 关注 2016.09.29 17:46* 字数 2868 阅读 22204评论 22喜欢 80 Webpack是目前基于React和Redux开发 ...
- Ceph:pg peering过程分析
转自:https://www.ustack.com/blog/ceph%ef%bc%8dpg-peering/ Peering:互为副本的三个(此处为设置的副本个数,通常设置为3)pg的元数据达到一致 ...
- 命令行连接db2数据库
在cmd界面执行db2cmd命令 然后在db2cmd界面执行db2命令 然后执行 CONNECT TO UIBS USER DB2INST1 USING 123456命令
- 31-THREE.JS 正方体
<!DOCTYPE html> <html> <head> <title>Example 05.04 - Basic 2D geometries - C ...
- FFT快速傅立叶变换
//最近突然发现博客园支持\(\rm\LaTeX\),非常高兴啊! 话说离省选只有不到五天了还在学新东西确实有点逗…… 切到正题,FFT还是非常神奇的一个东西,能够反直觉地把两个多项式相乘的时间复杂度 ...
- Database项目中关于Procedure sp_refreshsqlmodule_internal的错误
最近项目中发现一怪问题,使用DB项目发布数据库时,总提示 “(110,1): SQL72014: .Net SqlClient Data Provider: Msg 1222, Level 16, S ...