【C++】满二叉树问题
- /*
- 给出一棵满二叉树的先序遍历,有两种节点:字母节点(A-Z,无重复)和空节点(#)。要求这个树的中序遍历。输出中序遍历时不需要输出#。
- 满二叉树的层数n满足1<=n<=5。
- Sample Input:
- ABC#D#E
- Sample Output:
- CBADE
- */
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<iostream>
- using namespace std;
- const int M=;
- char data[M];
- int layer;
- struct node
- {
- char data;
- struct node *l;
- struct node *r;
- };
- void build(node * & t,int l)
- {
- if(l>layer)
- return ;
- int i=;
- while(data[i]=='\0')
- i++;
- char tc=data[i];
- //cout<<i<<endl<<tc<<endl;
- data[i]='\0';
- if(tc=='#')
- {
- t=NULL;
- return ;
- }
- t=new node();
- t->data=tc;
- build(t->l,l+);
- build(t->r,l+);
- }
- void display(node *t)
- {
- if(t==NULL)
- return ;
- display(t->l);
- printf("%c",t->data);
- display(t->r);
- }
- int main()
- {
- /*
- printf("%d\n",(int)(log(8)/log(2)));
- printf("%f\n",(log(7)/log(2)));
- */
- memset(data,'\0',sizeof(data));
- while(scanf("%s",&data))
- {
- //printf("%s\n",data);
- int n=strlen(data)+;
- /*
- if(log(n)/log(2)>(int)(log(n)/log(2)))
- layer=(int)(log(n)/log(2))+1;
- else*/
- layer=(int)(log(n)/log());
- //printf("%d\n",layer);
- node *tree;
- build(tree,);
- display(tree);
- }
- return ;
- }
tz@HZAU
2019/3/13
【C++】满二叉树问题的更多相关文章
- UVA 712-S-Trees(满二叉树的简单查询)
题意:给一棵满二叉树,叶子节点赋予权值,0或者1,对于每个查询输出叶子节点的权值,每个查询0代表往左走,1代表往右走,这题坑的地方是层的访问顺序,如第二组测试,由上到下依次是x3,x1,x2,假如给一 ...
- [Swift]LeetCode894. 所有可能的满二叉树 | All Possible Full Binary Trees
A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list of al ...
- python实现满二叉树递归循环
一.二叉树介绍点这片文章 二叉树及题目介绍 例题: 有一颗满二叉树,每个节点是一个开关,初始全是关闭的,小球从顶点落下, 小球每次经过开关就会把它的状态置反,这个开关为关时,小球左跑,为开时右跑.现在 ...
- PAT甲级题解-1123. Is It a Complete AVL Tree (30)-AVL树+满二叉树
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6806292.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 树&二叉树&&满二叉树&&完全二叉树&&完满二叉树
目录 树 二叉树 完美二叉树(又名满二叉树)(Perfect Binary Tree) 完全二叉树(Complete Binary Tree) 完满二叉树(Full Binary Tree) 树 名称 ...
- 【algo&ds】【吐血整理】4.树和二叉树、完全二叉树、满二叉树、二叉查找树、平衡二叉树、堆、哈夫曼树、B树、字典树、红黑树、跳表、散列表
本博客内容耗时4天整理,如果需要转载,请注明出处,谢谢. 1.树 1.1树的定义 在计算机科学中,树(英语:tree)是一种抽象数据类型(ADT)或是实作这种抽象数据类型的数据结构,用来模拟具有树状结 ...
- [LeetCode] 894. All Possible Full Binary Trees 所有可能的满二叉树
A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list of al ...
- 二叉树&满二叉树与完全二叉树
二叉树的定义 二叉树(Binary Tree)是n(n≥0)个元素的有限集合,该集合为空或者为由一个称为"根"的元素及两个不相交的.被分别称为左子树和右子树的二叉树组成 二叉树的基 ...
- 找出 int 数组的平衡点 & 二叉树 / 平衡二叉树 / 满二叉树 / 完全二叉树 / 二叉查找树
找出 int 数组的平衡点 左右两边和相等, 若存在返回平衡点的值(可能由多个); 若不存在返回 -1; ``java int [] arr = {2,3,4,2,4}; ```js const ar ...
随机推荐
- (转)Java代码书写规范
0. 安装阿里代码规范的eclipse插件 https://www.cnblogs.com/caer/p/7753522.html 1.基本原则 强制性原则: 1.字符串的拼加操作,必须使用S ...
- torch分类问题
import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.p ...
- 3D Slicer中文教程(四)—图像分割
1.数据获取 (1)下载3D Slicer自带的样本数据 (2)选择自由的数据 (3)网上数据库等其他方式下载数据 2.分割工具 Segment Editor是一个用于分割的模块.细分(也称为轮廓)描 ...
- 【原创】大数据基础之ElasticSearch(2)常用API整理
Fortunately, Elasticsearch provides a very comprehensive and powerful REST API that you can use to i ...
- 【原创】运维基础之Docker(2)通过docker部署zookeeper nginx tomcat redis kibana/elasticsearch/logstash mysql kafka mesos/marathon
通过docker可以从头开始构建集群,也可以将现有集群(配置以及数据)平滑的迁移到docker部署: 1 docker部署zookeeper # usermod -G docker zookeeper ...
- JS函数可以再添加属性(包括方法)
1 前言 JS函数可以再添加属性(包括方法),这个有点有趣,记录一下. 2 代码 <!DOCTYPE html> <html> <head> <title&g ...
- CentOS7.6编译安装nginx
配置阿里云yum源 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak wget -O /etc/yu ...
- OrCAD Capture CIS 16.6 将版本16.6的设计文件另存为版本16.2的设计文件
操作系统:Windows 10 x64 工具1:OrCAD Capture CIS 16.6-S062 (v16-6-112FF) 启动OrCAD Capture CIS,打开.dsn设计文件,右击该 ...
- centos查看系统/硬件信息及运维常用命令
[root@yan-001 ~] # uname -a # 查看内核/操作系统/CPU信息的linux系统信息命令 [root@yan-001 ~] # head -n 1 /etc/issue # ...
- Vue中父子组件通讯——组件todolist
一.todolist功能开发 <div id="root"> <div> <input type="text" v-model=& ...