当前位置:网站首页>6-3 non recursive traversal of binary tree
6-3 non recursive traversal of binary tree
2022-06-22 21:55:00 【White -】
6-3 Non recursive traversal of binary trees
This problem requires a non recursive method to achieve a given binary tree 3 Kind of traversal .
Function interface definition :
void InorderTraversal( BinTree BT );
void PreorderTraversal( BinTree BT );
void PostorderTraversal( BinTree BT );
among BinTree The structure is defined as follows :
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
int flag;
};
requirement 3 Each function prints out the content of the node in the order of access , The format is a space followed by a character .
Besides , A complete set of stack operations is given in the referee program , Can be called directly .
Sample referee test procedure :
#include <stdio.h>
#include <stdlib.h>
typedef enum { false, true } bool;
typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
int flag;
};
/------ The definition of the stack -------/
typedef Position SElementType;
typedef struct SNode *PtrToSNode;
struct SNode {
SElementType Data;
PtrToSNode Next;
};
typedef PtrToSNode Stack;
/* The referee realizes , Details don't show /
Stack CreateStack();
bool IsEmpty( Stack S );
bool Push( Stack S, SElementType X );
SElementType Pop( Stack S ); / Delete and return only S Top element of /
SElementType Peek( Stack S );/ Return only S Top element of /
/---- End of stack definition -----*/
BinTree CreateBinTree(); /* The referee realizes , Details don't show */
void InorderTraversal( BinTree BT );
void PreorderTraversal( BinTree BT );
void PostorderTraversal( BinTree BT );
int main()
{
BinTree BT = CreateBinTree();
printf(“Inorder:”); InorderTraversal(BT); printf(“\n”);
printf(“Preorder:”); PreorderTraversal(BT); printf(“\n”);
printf(“Postorder:”); PostorderTraversal(BT); printf(“\n”);
return 0;
}
/* Your code will be embedded here */
sample input :
Pictured 
sample output :
Inorder: D B E F A G H C I
Preorder: A B D F E C G H I
Postorder: D E F B H G I C A
Code :
void InorderTraversal( BinTree BT ){
if(BT==NULL)
return ;
InorderTraversal(BT->Left);
printf(" %c",BT->Data);
InorderTraversal(BT->Right);
}
void PreorderTraversal( BinTree BT ){
if(BT==NULL)
return ;
printf(" %c",BT->Data);
PreorderTraversal(BT->Left);
PreorderTraversal(BT->Right);
}
void PostorderTraversal( BinTree BT ){
if(BT==NULL)
return ;
PostorderTraversal(BT->Left);
PostorderTraversal(BT->Right);
printf(" %c",BT->Data);
}
202206201635 One
边栏推荐
- 校园跑腿管理端APP—陕西格创
- Introduce sparse activation mechanism! Uni perceiver MOE significantly improves the performance of generalist model
- 6-5 图的深度遍历-邻接矩阵实现
- Cannot re-register id: PommeFFACompetition-v0问题解决
- Watch,computed和methods的区别
- [book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!
- IDC發布中國數據治理報告 億信華辰第一
- Jerry's near end tone change problem of opening four channel call [chapter]
- Lesson 016: sequence | after class test questions and answers
- Lesson 025: Dictionary: after class test questions and answers when the index is not easy to use
猜你喜欢

Lesson 025: Dictionary: after class test questions and answers when the index is not easy to use
![Jerry's near end tone change problem of opening four channel call [chapter]](/img/03/f08cd660c1c602aa08218c4c791ec3.png)
Jerry's near end tone change problem of opening four channel call [chapter]

Lesson 019: function: my site listen to my after-school test questions and answers

IDC releases China Data Governance Report Yixin Huachen No. 1

科研热点|官宣!2022年JCR分区和影响因子发布时间确定!

Cannot re-register id: PommeFFACompetition-v0问题解决

CVPR2022 | 海德堡大学《深度视觉相似性与度量学习》教程

分享insert into select遇到的死锁问题(项目实战)

6-7 图的深度遍历-邻接表实现

Lesson 014-15: string (see lesson 27-32 of the new version of little turtle) | after class test questions and answers
随机推荐
第027讲:集合:在我的世界里,你就是唯一 | 课后测试题及答案
84- I am on Internet & lt; 52 SQL statement performance optimization strategies & gt; Some views of
牛客 52次月赛 C 说谎的机器 (区间赋值操作由O(n^2)转为O(n)的复杂度)
(DUC/DDC)数字上混频/正交下混频原理及matlab仿真
Cannot re register id: pommeffacompetition-v0 problem solving
基于AI驱动大分子药物发现,「华深智药」获近5亿元A轮融资
长安旗下阿维塔科技增资扩股落定:宁德时代将持股约24%!
5分钟快速上线Web应用和API(Vercel)
Jerry's problem of opening the near end of four channel call [chapter]
第033讲:异常处理:你不可能总是对的2 | 课后测试题及答案
72 results and development suggestions of the latest on-site production system optimization
(duc/ddc) digital up mixing / quadrature down mixing principle and MATLAB simulation
Lesson 026: Dictionary: when the index is not easy to use 2 | after class test questions and answers
Redis usage scenario sharing (project practice)
Lesson 018: function: flexible is powerful after class test questions and answers
LeetCode#20.有效的括号
第028讲:文件:因为懂你,所以永恒 | 课后测试题及答案【无标题】
An example of 89 Oracle SQL writing and optimizer defects
71- analysis of an Oracle DBA interview with Alibaba in 2010
数据库总结:mysql在开发过程中常见的问题及优化