/*
给出一棵满二叉树的先序遍历,有两种节点:字母节点(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++】满二叉树问题的更多相关文章

  1. UVA 712-S-Trees(满二叉树的简单查询)

    题意:给一棵满二叉树,叶子节点赋予权值,0或者1,对于每个查询输出叶子节点的权值,每个查询0代表往左走,1代表往右走,这题坑的地方是层的访问顺序,如第二组测试,由上到下依次是x3,x1,x2,假如给一 ...

  2. [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 ...

  3. python实现满二叉树递归循环

    一.二叉树介绍点这片文章 二叉树及题目介绍 例题: 有一颗满二叉树,每个节点是一个开关,初始全是关闭的,小球从顶点落下, 小球每次经过开关就会把它的状态置反,这个开关为关时,小球左跑,为开时右跑.现在 ...

  4. PAT甲级题解-1123. Is It a Complete AVL Tree (30)-AVL树+满二叉树

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6806292.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  5. 树&二叉树&&满二叉树&&完全二叉树&&完满二叉树

    目录 树 二叉树 完美二叉树(又名满二叉树)(Perfect Binary Tree) 完全二叉树(Complete Binary Tree) 完满二叉树(Full Binary Tree) 树 名称 ...

  6. 【algo&ds】【吐血整理】4.树和二叉树、完全二叉树、满二叉树、二叉查找树、平衡二叉树、堆、哈夫曼树、B树、字典树、红黑树、跳表、散列表

    本博客内容耗时4天整理,如果需要转载,请注明出处,谢谢. 1.树 1.1树的定义 在计算机科学中,树(英语:tree)是一种抽象数据类型(ADT)或是实作这种抽象数据类型的数据结构,用来模拟具有树状结 ...

  7. [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 ...

  8. 二叉树&满二叉树与完全二叉树

    二叉树的定义 二叉树(Binary Tree)是n(n≥0)个元素的有限集合,该集合为空或者为由一个称为"根"的元素及两个不相交的.被分别称为左子树和右子树的二叉树组成 二叉树的基 ...

  9. 找出 int 数组的平衡点 & 二叉树 / 平衡二叉树 / 满二叉树 / 完全二叉树 / 二叉查找树

    找出 int 数组的平衡点 左右两边和相等, 若存在返回平衡点的值(可能由多个); 若不存在返回 -1; ``java int [] arr = {2,3,4,2,4}; ```js const ar ...

随机推荐

  1. pythonのdjango CSRF简单使用

    一.简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成.而对于django中设置防跨站请求伪造功 ...

  2. Django之权限

    关于rbac: (1) 创建表关系: class User(models.Model): name=models.CharField(max_length=32) pwd=models.CharFie ...

  3. Web从入门到放弃<5>

    <1> CSS_DOM 1,structural layer 2,presentation layer 3,behavior layer style也是一个属性 <!DOCTYPE ...

  4. javascipt继承机制(from阮一峰)

    Javascript继承机制的设计思想   我一直很难理解Javascript语言的继承机制. 它没有"子类"和"父类"的概念,也没有"类" ...

  5. 【原创】大叔问题定位分享(21)spark执行insert overwrite非常慢,比hive还要慢

    最近把一些sql执行从hive改到spark,发现执行更慢,sql主要是一些insert overwrite操作,从执行计划看到,用到InsertIntoHiveTable spark-sql> ...

  6. css的transform属性让子元素在父元素里面垂直水平居中

  7. chromerdriver下载地址:xpath_help

    chrome下载地址 http://npm.taobao.org/mirrors/chromedriver xpath_help https://blog.csdn.net/Cayny/article ...

  8. 【web】服务器推送的实现方式(转)

    轮询 http流 websocket   https://www.cnblogs.com/freud/p/8397934.html http2.0 浅谈Websocket.Ajax轮询和长连接(lon ...

  9. ReSharper反编译C#类库

    经常会在使用C#类中的某个函数时想了解其中具体的代码,可是F12转到定义后只能看到函数简单的声明, 看不到方法体中的代码,这挺让人沮丧的.. 如下: F12进入后显示的是元数据, Equals函数只能 ...

  10. python数据类型一:字符串

    Python 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello W ...