当前位置:网站首页>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
边栏推荐
- 第033讲:异常处理:你不可能总是对的2 | 课后测试题及答案
- 第021讲:函数:lambda表达式 | 课后测试题及答案
- 6月25日PMI认证考点防疫要求及考场安排
- 微软 Edge 浏览器将支持网络测速,内置计算器和单位转换工具
- Summary of differences between localstorage, sessionstorage and cookies
- 第026讲:字典:当索引不好用时2 | 课后测试题及答案
- Redis usage scenario sharing (project practice)
- Jerry's plug-in 4m flash to view the processing method with a size of only 1m on the PC [chapter]
- 杰理之动态切换 EQ 文件【篇】
- Kali2021 installing the rtl8188gu wireless network card [tl-wn726n] driver
猜你喜欢

Redis的使用场景分享(项目实战)

Introduce sparse activation mechanism! Uni perceiver MOE significantly improves the performance of generalist model
![[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!](/img/f0/4f237e7ab1bff9761b6092dd4ef3d9.png)
[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 publie le rapport sur la gouvernance des données en Chine

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

杰理之AUX 模式使用 AUX1或者 AUX2通道时,程序会复位问题【篇】

Optimization solver | gurobi's Mvar class: a sharp tool for matrix modeling and an alternative solution to dual problems (with detailed cases and codes attached)

Can the characteristics of different network structures be compared? Ant & meituan & NTU & Ali proposed a cross architecture self supervised video representation learning method CaCl, performance SOTA

Lesson 033: exception handling: you can't always be right 2 | after class test questions and answers
![Jerry's dynamic switching EQ document [chapter]](/img/2d/9a0245b87fb05ea61dbfc7922ea766.png)
Jerry's dynamic switching EQ document [chapter]
随机推荐
Lesson 019: function: my site listen to my after-school test questions and answers
The interception of Chinese and English strings in Oracle database is different
Jerry's dynamic switching EQ document [chapter]
Oracle数据库中文字符串和英文字符串的截取不同
第032讲:异常处理:你不可能总是对的 | 课后测试题及答案
6-3 二叉树的非递归遍历
PHP image making
TC397 Flash
How to operate redis on the IntelliJ idea database console
IDC發布中國數據治理報告 億信華辰第一
软考必备资料大放送,全科目软考资料都给你备好了!
es 按条件查询数据总条数
73- find the SQL example during the business peak period (report development class)
RuntimeError: CUDA error: CUBLAS_ STATUS_ EXECUTION_ FAILED when calling `cublasSgemmStridedBatched( ha
[513. find the value in the lower left corner of the tree]
How swiftui simulates the animation effect of view illumination increase
RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemmStridedBatched( ha
优化求解器 | Gurobi的MVar类:矩阵建模利器、求解对偶问题的备选方案 (附详细案例+代码)
7-1 前序序列创建二叉树
杰理之开启四声道通话近端卡顿问题【篇】