PTA 中序输出度为1的结点
本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树中度为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;
}
/* 你的代码将被嵌在这里 */
输出样例(对于图中给出的树):
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);
}
PTA 中序输出度为1的结点的更多相关文章
- PTA 中序输出度为2的结点
6-10 中序输出度为2的结点 (10 分) 本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树中度为2的结点. 函数接口定义: void InorderPrintNodes( BiTree ...
- PTA 中序输出叶子结点
6-8 中序输出叶子结点 (10 分) 本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树的叶结点. 函数接口定义: void InorderPrintLeaves( BiTree T); T ...
- 二叉树的先序、中序以及后序遍历(递归 && 非递归)
树节点定义: class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } 递归建立二 ...
- 《剑指offer》-中序遍历下一个节点
题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. /* struct TreeLinkNode { in ...
- 《剑指offer》第八题(重要!查找二叉树的中序遍历的下一个结点)
文件一:main.cpp // 面试题:二叉树的下一个结点 // 题目:给定一棵二叉树和其中的一个结点,如何找出中序遍历顺序的下一个结点? // 树中的结点除了有两个分别指向左右子结点的指针以外,还有 ...
- 【Offer】[8] 【中序遍历的下一个结点】
题目描述 思路分析 Java代码 代码链接 题目描述 给定一棵二叉树和其中的一个结点,如何找出中序遍历顺序的下一个结点? 树中的结点除了有两个分别指向左右子结点的指针以外,还有一个指向父结点的指针. ...
- PAT甲级|1151 LCA in a Binary Tree 先序中序遍历建树 lca
给定先序中序遍历的序列,可以确定一颗唯一的树 先序遍历第一个遍历到的是根,中序遍历确定左右子树 查结点a和结点b的最近公共祖先,简单lca思路: 1.如果a和b分别在当前根的左右子树,当前的根就是最近 ...
- 二叉排序树的构造 && 二叉树的先序、中序、后序遍历 && 树的括号表示规则
二叉排序树的中序遍历就是按照关键字的从小到大顺序输出(先序和后序可没有这个顺序) 一.以序列 6 8 5 7 9 3构建二叉排序树: 二叉排序树就是中序遍历之后是有序的: 构造二叉排序树步骤如下: 插 ...
- PAT A1020——已知后序中序遍历求层序遍历
1020 Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Give ...
随机推荐
- 我是sakebow:新人报到,请多关照!
大家好 这里是sakebow,实际上是从CSDN转生过来的(说得好像在CSDN死了一样),在那边是ordinary_brony.我的GitHub名字也是sakebow 来这里干什么 主要还是想试试做个 ...
- Swift 5.3
Swift 5.3 https://swift.org/blog/ refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- how to disabled prefers-color-scheme in js & dark theme
how to disabled prefers-color-scheme in js dark theme https://developer.mozilla.org/en-US/docs/Web/C ...
- js repeatify & no for loop
js repeatify & no for loop js repeatify https://www.sitepoint.com/5-typical-javascript-interview ...
- free online business card generator
free online business card generator 免费在线名片生成器 https://www.logaster.cn/business-card/ https://www.chu ...
- how to drag a tab to open it in a new window
how to drag a tab to open it in a new window 在新的窗口中打开拖拽的 tab? https://superuser.com/questions/131928 ...
- Open API collection
Open API collection online API https://developer.github.com/v3/ https://developer.github.com/v4 http ...
- scrimba & interactive free online tutorials
scrimba & interactive free online tutorials https://github.com/scrimba/community/blob/master/FAQ ...
- py 使用win32 api
http://timgolden.me.uk/pywin32-docs/contents.html https://docs.python.org/3/library/ctypes.html#ctyp ...
- ip & 0.0.0.0 & 127.0.0.1 & localhost
ip & 0.0.0.0 & 127.0.0.1 7 localhost host https://www.howtogeek.com/225487/what-is-the-diffe ...