1. #include<stdio.h>
  2. #include<malloc.h>
  3. #include<iostream>
  4.  
  5. //定义节点
  6. typedef struct BiNode{
  7. char data;
  8. struct BiNode *lch;
  9. struct BiNode *rch;
  10. }BiNode,*BiTree;
  11.  
  12. //先序拓展序列建立二叉树
  13. void Create(BiTree &T)
  14. {
  15. T =(BiNode*) malloc (sizeof(BiNode));
  16.  
  17. printf("Enter the data \n");
  18. scanf(" %c",&T->data);
  19. if(T->data=='#') T = NULL;
  20. if(T){
  21. printf("");
  22. Create(T->lch);
  23. Create(T->rch);
  24. }
  25. }
  26.  
  27. //先序遍历 (递归)
  28. void Preorder (BiTree T)
  29. {
  30. if (T) {
  31. printf(" %c",T->data); // 访问根结点
  32.  
  33. Preorder(T->lch); // 遍历左子树
  34. Preorder(T->rch);// 遍历右子树
  35. }
  36. }
  37.  
  38. //中序遍历 (递归)
  39. void Inorder (BiTree T)
  40. {
  41. if(T) {
  42. Inorder(T->lch);
  43.  
  44. printf(" %c",T->data);
  45.  
  46. Inorder(T->rch);
  47. }
  48. }
  49.  
  50. //后序遍历 (递归)
  51. void Postorder (BiTree T)
  52. {
  53. if(T) {
  54. Postorder(T->lch);
  55. Postorder(T->rch);
  56.  
  57. printf(" %c",T->data);
  58. }
  59. }
  60.  
  61. int main()
  62. {
  63. //建树
  64. printf("The fuction Create() is called.\n");
  65. BiTree T;
  66. Create(T);
  67.  
  68. //三种遍历递归算法
  69. printf("\n");
  70. printf("The fuction Preorder() is called.\n");
  71. Preorder(T);
  72.  
  73. printf("\n");
  74. printf("The fuction Inorder() is called.\n");
  75. Inorder(T);
  76.  
  77. printf("\n");
  78. printf("The fuction Postorder() is called.\n");
  79. Postorder(T);
  80.  
  81. printf("\n");
  82. system("pause");
  83.  
  84. }

二叉树[C实现]的更多相关文章

  1. [saiku] 源码整合[maven整合]

    saiku源码的整合分为[普通web项目整合]和[maven整合]两种 本节主要是讲解如何整合为maven项目 转载自:http://blog.csdn.net/gsying1474/article/ ...

  2. [terry笔记]Oracle会话追踪(二):TKPROF

    接上一笔记[terry笔记]Oracle会话追踪(一):SQL_TRACE&EVENT 10046 http://www.cnblogs.com/kkterry/p/3279282.html ...

  3. [terry笔记]Oracle会话追踪(一):SQL_TRACE&EVENT 10046

      SQL_TRACE/10046 事件是 Oracle 提供的用于进行 SQL 跟踪的手段,在日常的数据库问题诊断和解决中是非常常用的方法.但其生成的trace文件需要tkprof工具生成一个可供人 ...

  4. [ Bubble Sort ]& block

    [ Bubble Sort ] 冒泡排序!“预处理.block.预编译”!<环境:Terminal的gcc编译器> 简述:冒泡排序就是把小的元素往前调或者把大的元素往后调.比较是相邻的两个 ...

  5. 洛谷 P1120 小木棍 [数据加强版]解题报告

    P1120 小木棍 [数据加强版] 题目描述 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50. 现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它 ...

  6. 洛谷——P1120 小木棍 [数据加强版]

    P1120 小木棍 [数据加强版] 题目描述 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过5050. 现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍 ...

  7. 洛谷 P1120 小木棍 [数据加强版]

    P1120 小木棍 [数据加强版] 题目描述 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50. 现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它 ...

  8. coffeeScript中类的多态[学习篇]

    类的一大应用就是多态.多态是一个面向对象编程的高级术语----“一个东西可编程很多不同的东西,但不是任何东西”.[引自coffeescript深入浅出] class Shape constructor ...

  9. CSU 1642 Problem B[难][前缀和]

    Description 已知两个正整数a和b,求在a与b之间(包含a和b)的所有整数的十进制表示中1出现的次数. Input 多组数据(不超过100000组),每组数据2个整数a,b.(1≤a,b≤1 ...

随机推荐

  1. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

  2. 写程序该选Mac 还是PC ?(转)

    原文链接:http://gogojimmy.net/2012/04/07/why-programmer-should-use-mac/ 序 一个竞争的市场,就会有对立的产生,这世界存在着很多不同的领域 ...

  3. Adapter 代码中启动报错

    安装好Adapter之后,在designer中可以启动Adapter,但在代码中启动却总是报错,“could not create RVMQSession"或者是“native implem ...

  4. 观点:BPM已经过时了?

    在这个信息爆炸的世界,业务转型通常是以数字系统和流程的方式发生. 根据Forrester的报告“软件必须丰富你的品牌”,人们要依靠这些技术实现期望的商业成果,比如品牌联系.客户服务创新.更好的产品和提 ...

  5. C#自定义属性(跟成员变量的区别)

    属性声明 public int age { get; set; } 从功能上等价于 private int m_age; public int age {get { return m_age; }se ...

  6. Centos配置SS5代理

    wget http://heanet.dl.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz tar xvf ss5-3.8.9-8 ...

  7. [转]ZendFramework数据库操作总结

    Zend_Db数据库知识 例子: Model文件: $this->fetchAll("is_jian=1","id DESC",0,2)->toAr ...

  8. LLBLGen Pro v4.2_Patch+Keygen

    将dll文件覆盖安装目录下的文件,之后用算号器算出license文件,将license文件放在安装目录下即可. 算号器是在http://www.dxper.net/thread-408-1-1.htm ...

  9. swift 定位

    iOS 8 及以上需要在info.plist文件中添加下面两个属性 NSLocationWhenInUseUsageDescription 使用应用期间 NSLocationAlwaysUsageDe ...

  10. JavaScript toFixed 用法

    在JS中进行乘法运算时 我们又是会遇到一下情况 <input type="text" id="num1" value="" /> ...