04-树6 Complete Binary Search Tree
2016-04-28 15:47
316 查看
用数组
ac代码
ac代码
#include<cstdio> #include<cstdlib> const int maxx = 1005; int node[maxx]; int tree[maxx]; int pos = 0,n; int cmp(const void *a,const void *b){ int *pa = (int *)a; int *pb = (int *)b; return *pa - *pb; } void build(int root) { if(root>n) return; int lson = root<<1,rson = (root<<1)+1; build(lson); tree[root] = node[pos++]; build(rson); } int main() { scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&node[i]); } qsort(node,n,sizeof(int),cmp); build(1); printf("%d",tree[1]); for(int i=2;i<=n;i++){ printf(" %d",tree[i]); } printf("\n"); return 0; }
相关文章推荐
- Where is the best place to put <script> tags in HTML markup?
- 网络图片框架
- Mysql中文乱码问题完美解决方案
- linux下oracle11g sys和system忘记密码
- Java Web的数据库操作
- thrift系列 - 快速入门
- [原创]Visual Studio 使用 Just My Code引起无法断点
- yum lock 解决方法
- valgrind
- 整理一些开源项目
- mysql如何用order by 自定义排序
- jQuery生成json对象
- stylus css 框架使用方法深入解析
- 【bug】对象激活前无法通过调用脚本函数设置变量
- 设计模式之Adapter
- JS实现监听事件,添加删除显示控件
- java观察者模式
- eclipse, Log4j配置(真心的详细~)
- 事件模拟场景:猫叫->老鼠逃跑 & 主人惊醒
- Android屏幕适配-----屏幕尺寸