几道笔试题的解法(三)

来源:互联网 发布:淘宝介入会打电话吗 编辑:程序博客网 时间:2024/05/01 07:57

题目:编写一个二叉树的中序遍历算法

分析:本题考查二叉树的遍历。

 

代码如下:(下面的代码采用的是递归遍历的算法)

 

typedef int ElemType;

 

typedef struct BinaryTree

{

         ElemType Data;

         struct BinaryTree * Left;

         struct BinaryTree * Right;

}BinTree, *pBinTree;

 

static void Print(pBinTree root)

{

         if (NULL != root)

         {

            printf(" %d/n", root-> Data);

         }

}

void MidOrder(pBinTree root)              //递归中序遍历

{

         if (NULL != root)

         {

            MidOrder (root-> Left);

            Print (root);

            MidOrder(root-> Right);

         }

 

 

 

原创粉丝点击