zoukankan      html  css  js  c++  java
  • 二叉树遍历

    /*
    先序建立二叉树,中序输出二叉树
    author:calm
    */

    #include<stdio.h>
    #include<malloc.h>
    #define OK 1
    #define FALSE 0
    typedef int status;
    typedef struct Node
    {
     status data;
     struct Node *LTree,*RTree;
    }BinaryTree;

    /*PreCreateTree先序创建BinaryTree*/
    void PreCreateTree(BinaryTree *head)
    {
     int ch=0;
     scanf("%d",&ch);
     if(ch=='#')
     {
      head=NULL;
     }
     else
     {
      head=(BinaryTree *)malloc(sizeof(BinaryTree));
      head->data=ch;
      PreCreateTree(head->LTree);
      PreCreateTree(head->RTree);
     }
    }
    void print(int data)
    {
     printf("%d ",data);
    }
    void InOrderTraverse(BinaryTree *head,void (*fun)(int num))
    {
     fun(head->data);
     InOrderTraverse(head->LTree,fun);
     InOrderTraverse(head->RTree,fun);
    }

    void main()
    {
     BinaryTree *head=NULL;
     printf("Input:");
     PreCreateTree(head);
     putchar('\n');
     InOrderTraverse(head,print);
     putchar('\n');
     getchar();
    }

  • 相关阅读:
    HGOI20191115 模拟赛 题解
    HGOI20191114 CSP模拟赛 反思
    HGOI 20191108 题解
    HGOI 20191107 题解
    HGOI 20191106 题解
    HGOI 20191105 题解
    HGOI 20191103am 题解
    HGOI 20191101am 题解
    HGOI 20191031am 题解
    新的博客!!!
  • 原文地址:https://www.cnblogs.com/calm/p/1151844.html
Copyright © 2011-2022 走看看