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

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

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

    函数接口定义:

    
    void InorderPrintNodes( BiTree T);
    

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

    其中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: G C E

    void InorderPrintNodes( BiTree T){
        if(T==NULL)
            return;
        InorderPrintNodes(T->lchild);
        if(T->lchild==NULL&&T->rchild!=NULL||T->lchild!=NULL&&T->rchild==NULL)
            printf(" %c",T->data);
        InorderPrintNodes(T->rchild);
    
    }
  • 相关阅读:
    PHP中使用CURL实现GET和POST请求
    ecstore关于smarty语法调用
    Linux 定时任务详解
    fzu 1753 Another Easy Problem
    zoj 2562 More Divisors
    poj 2992 Divisors
    UVA10078多边形判断凹凸性
    UVA10002求凸包的质心
    UVA10088多边形内整点个数计算(计算几何)
    HDU 1824 简单2-sat
  • 原文地址:https://www.cnblogs.com/DirWang/p/11930009.html
Copyright © 2011-2022 走看看