HDu1710(二叉树)
来源:互联网 发布:php源码 网络验证 编辑:程序博客网 时间:2024/06/08 14:10
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1710
更多介绍:http://blog.csdn.net/lhfight/article/details/7788291
package D0726;import java.util.Scanner;public class HDU1710 {static String str;public static void main(String[] args) {Scanner sc = new Scanner(System.in);String[] strpre;//这里要用数组接受输入String[] strin;int n;while (sc.hasNext()) {n = sc.nextInt();strpre = new String[n];strin = new String[n];str = "";for (int i = 0; i < n; i++)strpre[i] = sc.next();for (int i = 0; i < n; i++)strin[i] = sc.next();Node3 node = buildTree(strpre, strin);postOrder(node);System.out.println(str.trim());}}// 建立二叉树public static Node3 buildTree(String[] strpre, String[] strin) {if (strpre.length <= 0)return null;// 建立一个根节点String s = strpre[0];Node3 root = new Node3(s);// 以根节点为中心,将中序分为两个子序列int i, index = 0;for (i = 0; i < strin.length; i++) {if (strin[i].equals(s)) {index = i;break;}}String[] leftin = new String[index];String[] rightin = new String[strin.length - index - 1];for (i = 0; i < index; i++)leftin[i] = strin[i];int j = index+1;for (i = 0; j < strin.length; i++,j++) rightin[i] = strin[j];// 根所左中序的长度,将先序分为左右两个子先序int leftlen = leftin.length;St…………………………………………………………………………<p style="COLOR: red; FONT-SIZE: 16px"><strong>原文:<a target=_blank href="http://www.verydemo.com/demo_c116_i106120.html" target="_blank">http://www.verydemo.com/demo_c116_i106120.html</a></strong></p>
0 0
- HDu1710(二叉树)
- HDU1710(二叉树遍历)
- HDu1710(二叉树)
- hdu1710 二叉树详解
- HDU1710二叉树构造
- hdu1710二叉树后序遍历
- HDU1710(根据前序和中序生成二叉树)
- HDU1710——Binary Tree Traversals(二叉树)
- 数据结构之二叉树的遍历 HDU1710 Binary Tree Traversals
- HDU1710 二叉树的前、中、后遍历
- hdu1710 Binary Tree Traversals(二叉树遍历)
- HDU1710 Binary Tree Traversals(二叉树重建模板609)
- HDU1710 Binary Tree Traversals(DFS,二叉树的遍历)
- 第一次写树hdu1710
- hdu1710
- hdu1710
- hdu1710
- HDU1710利用二叉树的先序和中序输出后序
- Android源码手机烧机脚本
- python--part4
- Csdn英雄会之平方子序列的个数
- 解决setMovementMethod(LinkMovementMethod.getInstance())后没有长按事件响应
- qt窗口显示出来后,再弹出一个小窗口
- HDu1710(二叉树)
- IOS_UI_day7_UITableView_优化
- 图书馆推荐阅读:香港大学推荐的44本经典书籍
- POJ-1001-Exponentiation
- [BASIC-30] 阶乘计算
- Eclipse+Jboss报java.lang.OutOfMemoryError:PermGen space异常的解决办法
- 微信公众平台开发入门视频教程已发布
- WCF学习笔记——配置服务引用
- ajax-file-upload IE出错