hiho第十周——后序遍历
来源:互联网 发布:软件架构重要性 编辑:程序博客网 时间:2024/06/05 21:13
hiho第十周——后序遍历
题目链接:http://hihocoder.com/problemset/problem/1049
注意点
string a = "1";string b = a.substr(0,0);string c = a.substr(0,1);string d = a.substr(1,0);string e = a.substr(1,1);
运行不会出错,结果是c=“1”其余都是空字符串。
可执行代码
#include<iostream>#include<fstream>#include<string>using namespace std;typedef struct Node{ char data; Node *left,*right;}Node;//后序遍历string houxu(Node * root){ string res; if(root==NULL) return res; string left = houxu(root->left); string right = houxu(root->right); return left+right+root->data;}Node* CreateTree(string pre,string mid){ int len = pre.size(); if(len==0) return NULL; int locate = mid.find(pre[0]); int left_len = locate; int right_len = len-locate-1; Node * node = new Node; node->data = pre[0]; node->left = CreateTree(pre.substr(1,left_len),mid.substr(0,left_len)); node->right = CreateTree(pre.substr(1+left_len,right_len),mid.substr(locate+1,right_len)); return node;}int main(){ //ifstream cin("input.txt"); string pre,mid; cin>>pre>>mid; Node *root = new Node; root = CreateTree(pre,mid); string ans = houxu(root); cout<<ans; return 0;}
0 0
- hiho第十周——后序遍历
- hiho刷题日记——第十天后序遍历
- [hiho]后序遍历
- hiho#1049 : 后序遍历( nyoj848 STBE)
- HIHO #1049 : 后序遍历 (dfs)
- HihoCoder第十周:后序遍历
- 第十周项目三 后序遍历二叉树
- hiho一下 第十一周——树中的最长路
- hiho 博弈——01(hiho 44周)
- hiho刷题日记——第十一天树中的最长路
- hiho刷题日记——第十三天最近公共祖先·一
- hiho刷题日记——第十七天最近公共祖先·三
- hiho刷题日记——第十八天RMQ问题再临
- hiho刷题日记——第十九天RMQ问题再临-线段树
- hiho第十四周
- 树的遍历—先序遍历、中序遍历、后序遍历
- 第十周项目一——验证算法之层序遍历算法的验证
- hiho第二周——Trie树
- 软键盘的收缩与展开
- Yii2 - 分页:在视图调用方法
- 机器学习最佳入门学习资料汇总
- YUV数据格式详解
- 学习一样新东西行而有效的方法
- hiho第十周——后序遍历
- linux下redis与phpredis安装详解与简单操作
- PHP正则获取图片信息
- 微软100题(95)递归判断数组是不是升序
- 关于Oracle数据库表中字段修改为自增
- android 内存泄露浅谈和处理
- ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
- Makefile-炼之道
- 提交Appstore遇到的错误