04-树6 Complete Binary Search Tree
此题要求根据输入数据得到该数据 的 完全二叉搜索树的层序遍历结果。那是不是要建完全二叉搜索树?怎么建?或者不建树得到结果?功力不够,都不会啊。
度娘一下,被别人的实现吓到了,感觉太复杂太长了,头疼~
然而又被别人的实现惊艳到了,太厉害了~
参考: https://blog.csdn.net/Roland_WuZF/article/details/49389995
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define MaxSize 1001 5 6 int Seq[MaxSize], LevelSeq[MaxSize]; 7 int j = 0; 8 9 int compare(const void *a, const void *b); 10 void InOrderStore(int root, int N); 11 12 int main() 13 { 14 int i, N; 15 scanf("%d", &N); 16 17 for ( i = 0; i < N; i++ ) { 18 scanf("%d", &Seq[i]); 19 } 20 // 排序 (increase) 得到 中序遍历的顺序 21 qsort(Seq, N, sizeof(int), compare); 22 23 InOrderStore(1, N); 24 25 printf("%d", LevelSeq[1]); 26 for ( i = 2; i <= N; i++ ) { 27 printf(" %d", LevelSeq[i]); 28 } 29 30 return 0; 31 } 32 /* 33 以 中序遍历 的方式 使用数组LevelSeq存储 中序遍历 得到的数组Seq, 34 */ 35 void InOrderStore(int root, int N) 36 { 37 if ( root <= N ) { 38 InOrderStore(root*2, N); 39 LevelSeq[root] = Seq[j++]; 40 InOrderStore(root*2+1, N); 41 } 42 } 43 44 int compare(const void *a, const void *b) 45 { 46 return ( *(int*)a - *(int*)b ); 47 }
转载于:https://www.cnblogs.com/wgxi/p/9998551.html
04-树6 Complete Binary Search Tree相关推荐
- 04-树6 Complete Binary Search Tree(30 分)
title: 04-树6 Complete Binary Search Tree(30 分) date: 2017-11-12 14:20:46 tags: - 完全二叉树 - 二叉搜索树 categ ...
- PAT甲级1064 Complete Binary Search Tree (30分):[C++题解]完全二叉搜索树BST
文章目录 题目分析 题目链接 题目分析 思路: 第一步,构造含有n个结点的完全二叉树:第二步,将n个数值填入,使其满足二叉搜索树的性质. 对于第一步: 完全二叉树用一维数组可以存下,不过从根结点的下标 ...
- C++学习之路 | PTA(甲级)—— 1064 Complete Binary Search Tree (30分)(带注释)(精简)
1064 Complete Binary Search Tree (30分) A Binary Search Tree (BST) is recursively defined as a binary ...
- (浙江大学数据结构)PTA Complete Binary Search Tree (10 分)
题目: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following prope ...
- [浙大数据结构] 04-树6 Complete Binary Search Tree (30分)
1 题目描述 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following pr ...
- 【数据结构笔记27】树习题:完全二叉搜索树(Complete Binary Search Tree)
本次笔记内容: 树习题-CBST. 1 数据结构的选择 树习题-CBST. 2 核心算法 树习题-CBST. 3 计算左子树的规模 文章目录 题意理解 分析:用链表还是数组表示树 核心算法 核心递归算 ...
- 1064 Complete Binary Search Tree (30 分)【难度: 一般 / 知识点: 完全二叉搜索树】
https://pintia.cn/problem-sets/994805342720868352/problems/994805407749357568 二叉搜索数的中序遍历是有序的.故先将权值排序 ...
- 1064. Complete Binary Search Tree
二叉排序树: http://www.patest.cn/contests/pat-a-practise/1064 1 #include <iostream> 2 #include < ...
- 笔试算法题(58):二分查找树性能分析(Binary Search Tree Performance Analysis)
议题:二分查找树性能分析(Binary Search Tree Performance Analysis) 分析: 二叉搜索树(Binary Search Tree,BST)是一颗典型的二叉树,同时任 ...
最新文章
- AAAI 2018经典论文获奖者演讲:本体论的昨天和今天
- vuex commit 模块_长篇连载:Vuex源码学习(二)脉络梳理
- I/O操作不占用CPU的任何线程
- Jenkins进阶-Gitlab使用Webhook实现Push代码自动部署(3)
- [转贴]彻底解决 CrystalReports 登录失败问题。
- spring实例化前的准备操作
- 文明4 java_文明4主题曲《Baba Yetu》(敬请关注中文歌词部分~)
- 安装SHARP MX-3618NC PCL6打印机驱动程序
- vvic/搜款网API接口(item_search-根据关键词取商品列表 )
- rocksdb-参数配置
- 又要数数小绵羊(四刷) kkmd66
- CTOlib码库介绍(GitHub热门项目收录网站)
- 计算机应用基础19秋在线作业2答案,东师计算机应用基础19秋在线作业2题目【标准答案】...
- 如何判断Android系统的版本
- 初学Java-----简单的猜数字小游戏
- 管理者运动初衷不是竞技,只为健康吗?
- Linux系统中的时间设置(硬件时钟VS系统时钟)
- Let the Flames Begin(约瑟夫环)
- Deepin Linux下更新nvidia独显驱动
- IP地址分类及特殊IP地址