forked from jyx-fyh/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryTree.h
More file actions
32 lines (30 loc) · 1.31 KB
/
binaryTree.h
File metadata and controls
32 lines (30 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Created by bubtcher on 23-10-21.
//
#ifndef ALGORITHM_BINARYTREE_H
#define ALGORITHM_BINARYTREE_H
#include"treenode.h"
#include<iostream>
#include <string>
#include <queue>
using std::cout, std::endl, std::string, std::queue;
void del(TreeNode* nd);//删除树
void preR(TreeNode* nd);//递归前序遍历
void inR(TreeNode* nd);//递归后续遍历
void postR(TreeNode* nd);//递归后续遍历
void pre(TreeNode* root);//非递归前序遍历1
void pre_1(TreeNode* root);//非递归前序遍历2
void in(TreeNode* root);//非递归中序遍历
void post(TreeNode* root);//非递归后续遍历
void layer(TreeNode* root);//层序遍历
string serializePre(TreeNode* root);//前序序列化
TreeNode* deserializePre(string str);//前序反序列化
string serializePost(TreeNode* root);//后续序列化
TreeNode* deserializePost(string str);//后续反序列化
string serializeLayer(TreeNode* root);//层序序列化
TreeNode* deserializeLayer(const string &str);//层序反序列化
void printTree(TreeNode* head);//打印树
TreeNode* generateRandomTreeLayer(int maxLayers, int maxVar);//随机创建一棵树,指定最大层数
TreeNode* generateRandomTreeNum(int numNodes, int maxVar);//随机创建一棵树,指定节点数
TreeNode* randomNode(TreeNode* root);//随机返回树中的一个节点
#endif //ALGORITHM_BINARYTREE_H