#include <stdio.h>
#include <stdlib.h>#define MAXSIZE 100;/*二叉树的数据结构定义*/
typedef struct BiTreeNode
{
char data;struct BiTreeNode *left;struct BiTreeNode *right;
}BiTreeNode,*BiTree;
/*二叉树的建立--按照先序方式建立--录入数据--插入*/
void CreateBiTree(BiTree *T)
{
char val;scanf("%c",&val);if(val == '#')*T = NULL; //NULL即表示为空二叉树else{
*T = (BiTree)malloc(sizeof(BiTreeNode));/* 申请一个结点存入数据 */(*T)->data = val;CreateBiTree(&(*T)->left);CreateBiTree(&(*T)->right);}
}/*二叉树的 先序遍历 根左右*/
void PreOrderTravel(BiTree T)
{
if(T == NULL)return ;printf("%c ", T->data);PreOrderTravel(T->left);PreOrderTravel(T->right);
}
/*二叉树的 中序遍历 左根右*/
void InOrderTravel(BiTree T)
{
if(T == NULL)return ;PreOrderTravel(T->left);printf("%c ", T->data);PreOrderTravel(T->right);
}
/*二叉树的 后序遍历 左右根*/
void TailOrderTravel(BiTree T)
{
if(T == NULL)return ;PreOrderTravel(T->left);PreOrderTravel(T->right);printf("%c ", T->data);
}int main()
{
BiTree T;T=(BiTree)malloc(sizeof(BiTreeNode));printf("请给二叉树按照先序遍历的输入顺序输入结点(空结点用符号'#'表示):\n");CreateBiTree(&T);printf("先序遍历的输出结果:\n");PreOrderTravel(T);printf("\n");printf("中序遍历的输出结果:\n");InOrderTravel(T);printf("\n");printf("后序遍历的输出结果:\n");TailOrderTravel(T);printf("\n");return 0;
}
详细解决方案
BiTree Recursion
热度:92 发布时间:2024-02-27 03:26:07.0
相关解决方案
- FF中出现too much recursion 异常
- ff上出现too much recursion ie崩溃的原因
- firedebug提醒 “too much recursion”
- 剑指 Offer 16. 数值的整数次方 产生错误:RecursionError: maximum recursion depth exceeded in comparison
- struts2:Infinite recursion detected
- 二叉树创建函数中一定要用指针的引用void createtree(BiTree *T)或者用指针的指针void createtree(BiTree **T)
- LeetCode(剑指offer-Recursion)-面试题16. 数值的整数次方
- LeetCode(剑指offer-Recursion)-面试题10- II. 青蛙跳台阶问题
- LeetCode(剑指offer-Recursion)-面试题10- I. 斐波那契数列
- python3 import logging报错:RecursionError: maximum recursion depth exceeded while calling a Python
- 递归(recursion)方法
- recursion versus iteration
- Recursion Vs Iteration
- Tail Recursion = 循环 = CPS
- RecursionError: maximum recursion depth exceeded in comparison
- 三、递归(Recursion)
- Summer Online Training Camp 1 for ICPC Training League (Recursion & Backtracking)
- Could not write JSON: Infinite recursion (StackOverflowError); (已解决)
- 数据结构预算法 — 递归算法(recursion)
- Recursion-tree Master Method
- python maximum recursion depth exceeded while calling a Python object
- BiTree Recursion
- recursion—快速排序