zoukankan      html  css  js  c++  java
  • PTA 中序输出度为2的结点

    6-10 中序输出度为2的结点 (10 分)
     

    本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树中度为2的结点。

    函数接口定义:

    
    void InorderPrintNodes( BiTree T);
    

    T是二叉树树根指针,InorderPrintNodes按照中序遍历的顺序输出给定二叉树T中度为2的结点,格式为一个空格跟着一个字符。

    其中BiTree结构定义如下:

    typedef struct BiTNode
    {
    	ElemType data;
    	struct BiTNode *lchild,*rchild;
    }BiTNode,*BiTree;
    

    裁判测试程序样例:

    
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef char ElemType;
    typedef struct BiTNode
    {
    	ElemType data;
    	struct BiTNode *lchild,*rchild;
    }BiTNode,*BiTree;
    
    BiTree Create();/* 细节在此不表 */
    void InorderPrintNodes( BiTree T);
    
    int main()
    {
    	BiTree T = Create();
    	printf("Nodes are:");
    	InorderPrintNodes(T);
    	return 0;
    }
    /* 你的代码将被嵌在这里 */
    

    输出样例(对于图中给出的树):

    二叉树.png

    Nodes are: D A
    
     
    void InorderPrintNodes( BiTree T){
        if(T==NULL)
            return;
        InorderPrintNodes(T->lchild);
        if(T->lchild!=NULL&&T->rchild!=NULL)
            printf(" %c",T->data);
        InorderPrintNodes(T->rchild);
    }
  • 相关阅读:
    腾讯云通信服务端返回签名
    synchronized同步语句块
    synchronized同步方法
    springjdbc的批量操作
    yield方法
    暂停线程
    【jdk源码学习】HashMap
    diamond types are not supported at this language level
    【java基础系列】一、常用命令行
    Socket通信综合示例
  • 原文地址:https://www.cnblogs.com/DirWang/p/11930018.html
Copyright © 2011-2022 走看看