博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT1043 BST 镜像管不了了
阅读量:4364 次
发布时间:2019-06-07

本文共 1519 字,大约阅读时间需要 5 分钟。

考虑到 出现相同的数等等

#include
#include
int cache[1001];int read=0,n;struct node*root;struct node{ int value; struct node* father; struct node* lchild; struct node* rchild;};void BuildTree(struct node*&Node,struct node*father){ Node=(struct node*)malloc(sizeof(struct node)); Node->lchild=Node->rchild=NULL; if(read==0) Node->father=NULL; //头节点 else Node->father=father; Node->value=cache[read++]; while(read
father&&Node->father->lchild==Node&&cache[read]>Node->father->value)// break; if(Node->father&&Node->father->rchild==Node&&cache[read]
father->value) break;*/ father=Node;//不好的习惯 一个变量两用 father改变用法了 while(father->father){//??? if(father->father->lchild==father&&cache[read]
father->value) father=father->father; else if(father->father->rchild==father&&cache[read]>=father->father->value) father=father->father; else return ; } if(cache[read]
value) BuildTree(Node->lchild,Node); else BuildTree(Node->rchild,Node); }}void postorder1(struct node*Node){ if(Node==NULL) return; postorder1(Node->lchild); postorder1(Node->rchild); if(read==n) read=0; else printf(" "); printf("%d",Node->value); };void postorder2(struct node*Node){ if(Node==NULL) return; postorder2(Node->lchild); postorder2(Node->rchild); if(root!=Node) printf(" "); printf("%d",-Node->value);};int main(){ int mirror=1; scanf("%d",&n); for(int i=0;i

  

转载于:https://www.cnblogs.com/lsj2020/p/5898061.html

你可能感兴趣的文章
SHELL日志分析 实例一
查看>>
闭包函数
查看>>
ZOJ Monthly, November 2012 - I - Search in the Wiki
查看>>
TextSwitcher,译为文字转换器控件
查看>>
C# 多线程编程(3):线程池ThreadPool
查看>>
Mac 使用技巧
查看>>
Whu 1603——Minimum Sum——————【单个元素贡献、滑窗】
查看>>
Windows下安装PHP扩展及资源下载地址(memcached为例)
查看>>
Node.js安装与配置 -- 收录
查看>>
hdu 4918
查看>>
队列- 链式存储-Java实现
查看>>
在 Ubuntu 下配置 C/C++ 开发环境【转】
查看>>
前端项目-代码开发规范(个人整理版)
查看>>
action-mapping
查看>>
HTML嵌套规则
查看>>
渗透测试方法及流程(转)
查看>>
Win下安装RabbitMQ的cookie问题
查看>>
有关楼层般的侧导航
查看>>
从网络上获取图片并保存在sdCard上
查看>>
oracle 体系结构解析
查看>>