Chinaunix首页 | 论坛 | 博客
  • 博客访问: 474101
  • 博文数量: 59
  • 博客积分: 345
  • 博客等级: 二等列兵
  • 技术积分: 1380
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-18 22:44
个人简介

to be myself

文章分类

全部博文(59)

文章存档

2017年(5)

2013年(47)

2012年(3)

2011年(4)

分类: C/C++

2013-03-02 15:58:45


点击(此处)折叠或打开

  1. 不必构造重新二叉树再遍历,输入已经告诉二叉树的状态了。
  2. #include <stdio.h>
  3. #include <string.h>

  4. int main()
  5. {
  6.     void Search(int n, char *s1, char *s2);
  7.     int n;
  8.     char s1[1000], s2[1000];
  9.     while (scanf("%s%s", s1, s2)!=EOF)
  10.     {
  11.         n = strlen(s1);
  12.         Search(n, s1, s2);
  13.         printf("n");
  14.     }
  15.     return 0;
  16. }

  17. void Search(int n, char *s1, char *s2)
  18. {
  19.     int p;
  20.     if (n <= 0)
  21.     {
  22.         return ;
  23.     }
  24.     p = strchr(s2, s1[0]) - s2;
  25.     Search(p, s1+1, s2); //PostOrder左子树
  26.     Search(n-p-1, s1+p+1, s2+p+1);//PostOrder右子树,p为根结点左边结点的个数
  27.     putchar(s1[0]);
  28. }
  29. //程序完
2010-08-19 14:08 发表于百度空间,今搬至CU。
阅读(1183) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~