PTA 中序输出叶子结点
本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树的叶结点。
函数接口定义:
void InorderPrintLeaves( BiTree T);
T是二叉树树根指针,InorderPrintLeaves按照中序遍历的顺序输出给定二叉树T的叶结点,格式为一个空格跟着一个字符。
其中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 InorderPrintLeaves( BiTree T);
int main()
{
BiTree T = Create();
printf("Leaf nodes are:");
InorderPrintLeaves(T);
return 0;
}
/* 你的代码将被嵌在这里 */
输出样例(对于图中给出的树):

Leaf nodes are: F G C
void InorderPrintLeaves( BiTree T){
if(T==NULL)
return;
InorderPrintLeaves(T->lchild);
if(T->lchild==NULL&&T->rchild==NULL)
printf(" %c",T->data);
InorderPrintLeaves(T->rchild);
}
PTA 中序输出叶子结点的更多相关文章
- PTA 中序输出度为2的结点
6-10 中序输出度为2的结点 (10 分) 本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树中度为2的结点. 函数接口定义: void InorderPrintNodes( BiTree ...
- PTA 中序输出度为1的结点
6-9 中序输出度为1的结点 (10 分) 本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树中度为1的结点. 函数接口定义: void InorderPrintNodes( BiTree T ...
- [PTA] 数据结构与算法题目集 6-11 先序输出叶结点
//函数PreorderPrintLeaves应按照先序遍历的顺序输出给定二叉树BT的叶结点,格式为一个空格跟着一个字符. void PreorderPrintLeaves(BinTree BT) { ...
- PTA 4-4 先序输出叶结点 【基础题】
//二叉树的叶结点:度为0的结点. void PreorderPrintLeaves( BinTree BT ) { if(BT==NULL) //如果传下来根节点就是空,直接返回: return; ...
- 二叉排序树的创建删除中序输出&&平衡树
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- 1064 Complete Binary Search Tree (30分)(已知中序输出层序遍历)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- Morris Traversal方法遍历二叉树(非递归,不用栈,O(1)空间)——无非是在传统遍历过程中修改叶子结点加入后继结点信息(传统是stack记录),然后再删除恢复
先看看线索二叉树 n个结点的二叉链表中含有n+1(2n-(n-1)=n+1)个空指针域.利用二叉链表中的空指针域,存放指向结点在某种遍历次序下的前驱和后继结点的指针(这种附加的指针称为"线索 ...
- C++编程练习(8)----“二叉树的建立以及二叉树的三种遍历方式“(前序遍历、中序遍历、后续遍历)
树 利用顺序存储和链式存储的特点,可以实现树的存储结构的表示,具体表示法有很多种. 1)双亲表示法:在每个结点中,附设一个指示器指示其双亲结点在数组中的位置. 2)孩子表示法:把每个结点的孩子排列起来 ...
- 图解中序遍历线索化二叉树,中序线索二叉树遍历,C\C++描述
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
随机推荐
- python xml转excle
<?xml version="1.0" encoding="UTF-8"?> <RECORDS xmlns:xsi="http:// ...
- SSL 数据加密原理简述
最近调试mqtt协议,为了保证数据安全性和将来客户端的对云的兼容性选择了openssl作为安全加密中间层,而没有使用私有的加密方式.所以花了点时间学习了一下ssl 加密流程整理如下: 因为正常正式使用 ...
- git-reset All In One
git-reset All In One git 撤销 merge $ git checkout feature-sentry $ git pull $ git checkout dev $ git ...
- React render twice bug
React render twice bug React bug constructor render twice bug update render twice bug StrictMode htt ...
- 转换 React 为TypeScript
转换 React 为TypeScript JavaScript import React from 'react'; import PropTypes from 'prop-types'; class ...
- js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit
js in depth: Object & Function & prototype & proto & constructor & classes inher ...
- vue $emit bug
vue $emit bug https://www.cnblogs.com/xgqfrms/p/11146189.html solution https://forum.vuejs.org/t/emi ...
- MySQL切换版本踩坑记录(包括恢复数据方法)
踩坑起因:在创建数据库时, 字段:create_time datetime DEFAULT CURRENT_TIMESTAMP, 报异常--Error Code: 1067 - Invalid def ...
- 【Python】set 与 list ——如何对列表进行去重?
在Python中,形如 {1,2,3,4,5} 这样的数据类型叫做"集合",外形酷似列表list [1,2,3,4,5] 但是集合与列表有很多区别,具体表现在以下几方面: List ...
- 死磕Spring之IoC篇 - Bean 的“前身”
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...