博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
二叉树遍历
阅读量:4107 次
发布时间:2019-05-25

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

#include
#include
struct Node{ Node *lchild; Node *rchild; char c;}Tree[50];int loc;Node *create(){ Tree[loc].lchild=Tree[loc].rchild=NULL; return &Tree[loc++];}char str1[30],str2[30];void postOrder(Node *T){ if(T->lchild!=NULL){ postOrder(T->lchild); } if(T->rchild!=NULL){ postOrder(T->rchild); } printf("%c",T->c);}Node *build(int s1,int e1,int s2,int e2){ Node *ret=create(); ret->c=str1[s1]; int rootIdx; for(int i=s2;i<=e2;i++){ if(str2[i]==str1[s1]){ rootIdx=i; break; } } if(rootIdx!=s2){ ret->lchild=build(s1+1,s1+(rootIdx-s2),s2,rootIdx-1); } if(rootIdx!=e2){ ret->rchild=build(s1+(rootIdx-s2)+1,e1,rootIdx+1,e2); } return ret;}int main(){ while(scanf("%s",str1)!=EOF){ scanf("%s",str2); loc=0; int L1=strlen(str1); int L2=strlen(str2); Node *T=build(0,L1-1,0,L2-1); postOrder(T);//后序遍历 printf("\n"); }}

 

转载地址:http://dnssi.baihongyu.com/

你可能感兴趣的文章
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
python __future__
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(二)
查看>>
pytorch(三)
查看>>
pytorch(四)
查看>>
pytorch(5)
查看>>
pytorch(6)
查看>>
opencv 指定版本下载
查看>>
ubuntu相关
查看>>
C++ 调用json
查看>>
nano中设置脚本开机自启动
查看>>
动态库调动态库
查看>>
Kubernetes集群搭建之CNI-Flanneld部署篇
查看>>
k8s web终端连接工具
查看>>