当前位置: 首页 > news >正文

2.5学习总结

今天看了二叉树,看的一脸懵,写了两道题

P4913:二叉树深度

#include <stdio.h>
#include <stdlib.h>
struct hly
{int left;int right;
}tree[1000005];
int hulingyun(int x)
{if(x==0)return 0;return 1+max(hulingyun(tree[x].left),hulingyun(tree[x].right));
}
int max(int a,int b)
{if(a>=b)return a;elsereturn b;
}
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++){int a,b;scanf("%d %d",&a,&b);tree[i].left=a;tree[i].right=b;}printf("%d",hulingyun(1));return 0;
}

P1305:新二叉树

#include <stdio.h>
#include <stdlib.h>
struct hly
{char left;char right;
}tree[205];
void hulingyun(char x)
{if(x=='*')return;printf("%c",x);hulingyun(tree[x].left);hulingyun(tree[x].right);
}
int main()
{int n;char m;scanf("%d",&n);scanf(" %c",&m);scanf("%c",&tree[m].left);scanf("%c",&tree[m].right);for(int i=2;i<=n;i++){char a;scanf(" %c",&a);scanf("%c",&tree[a].left);scanf("%c",&tree[a].right);}hulingyun(m);return 0;
}
http://www.lryc.cn/news/531913.html

相关文章:

  • java进阶文章链接
  • vue2+vue3 HMCXY基础入门
  • 一次线程数超限导致的hive写入hbase作业失败分析
  • ip属地是手机号还是手机位置?一文理清
  • 查看设备uuid
  • C_C++输入输出(下)
  • All in one 的 AI tool Chain “Halomate”
  • crewai框架第三方API使用官方RAG工具(pdf,csv,json)
  • 脉冲信号傅里叶变换与频域分析:从计算到理解
  • 6.【BUUCTF】[SUCTF 2019]CheckIn
  • 基于springboot的体质测试数据分析及可视化设计
  • 孟加拉国_行政边界省市边界arcgis数据shp格式wgs84坐标
  • 可视化相机pose colmap形式的相机内参外参
  • 数据结构 树2
  • GB/T 44721-2024 与 L3 自动驾驶:自动驾驶新时代的基石与指引
  • AURIX TC275学习笔记3 官方例程 (UART LED WDT)
  • Vim的基础命令
  • Linux的简单使用和部署4asszaaa0
  • Linux 的 sysfs 伪文件系统介绍【用户可以通过文件操作与内核交互(如调用内核函数),而无需编写内核代码】
  • 每日一题洛谷P5721 【深基4.例6】数字直角三角形c++
  • 计算机网络笔记再战——理解几个经典的协议1
  • ElasticSearch学习笔记-解析JSON格式的内容
  • 浅谈密码相关原理及代码实现
  • Spring Boot常用注解深度解析:从入门到精通
  • can not add outlook new accounts on the outlook
  • 私有化部署 DeepSeek + Dify,构建你的专属私人 AI 助手
  • 【Elasticsearch】post_filter
  • 验证工具:GVIM和VIM
  • 如何优化垃圾回收机制?
  • beyond the ‘PHYSICAL‘ memory limit.问题处理