Go to the documentation of this file.
14 #ifndef INCLUDE_TEST0_HH_
15 #define INCLUDE_TEST0_HH_
39 static bool GenTreeData(
const char *_file_path =
"./test0.txt",
const char *empty_flag =
"@")
41 std::string file_path(_file_path);
44 std::string cmd = std::string(
"DEL /P \"") + file_path +
'"';
46 system(
"echo We are trying to delete some files, which will be created later.");
57 std::ifstream fin(file_path.c_str(), std::ios_base::in);
60 std::cerr <<
"文件已存在!\n";
68 std::ofstream fout(file_path.c_str(), std::ios_base::out);
71 std::cerr <<
"无写权限,文件生成失败!\n";
78 <<
"B\tE\t" << empty_flag <<
"\tD\n"
79 << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' <<
"W\t" << empty_flag <<
'\n'
80 << empty_flag <<
"\tX\n"
81 << empty_flag <<
'\t' << empty_flag << std::endl;
86 system(
"echo File created successfully!");
92 std::cerr <<
"无法生成文件!\n";
107 template <
typename T,
typename Comparator>
110 out <<
"二叉树的规模(递归 非递归):\n"
112 out <<
"\n二叉树的高(深)度(递归 非递归),从0起:\n"
114 out <<
"\n前序遍历(递归):\n";
116 out <<
"\n前序遍历(非递归):\n";
118 out <<
"\n中序遍历(递归):\n";
120 out <<
"\n中序遍历(非递归):\n";
122 out <<
"\n后序遍历(递归):\n";
124 out <<
"\n后序遍历(非递归):\n";
128 out <<
"\n层次打印(调用lchild(), rchild(), root()等API):\n";
void inOrder_loop(std::ostream &out=std::cout) const
中序遍历(非递归版本)
void preOrder_loop(std::ostream &out=std::cout) const
前序遍历(非递归版本)
size_type height_loop() const
返回二叉树的高度(非递归版本)
size_type size() const
返回二叉树的结点数(递归版本)
void levelOrder(std::ostream &out=std::cout) const
层次遍历
void inOrder(std::ostream &out=std::cout) const
中序遍历(递归版本)
size_type size_loop() const
返回二叉树的结点数(非递归版本)
size_type height() const
返回二叉树的高度(递归版本)
void postOrder_loop(std::ostream &out=std::cout) const
后序遍历(非递归版本)
static void print_test_result(const binaryTree< T, Comparator > &binary_tree, const typename binaryTree< T, Comparator >::value_type &flag, std::ostream &out=std::cout)
(测试用)将一棵二叉树的遍历结果插到输出流
void postOrder(std::ostream &out=std::cout) const
后序遍历(递归版本)
void preOrder(std::ostream &out=std::cout) const
前序遍历(递归版本)
static bool GenTreeData(const char *_file_path="./test0.txt", const char *empty_flag="@")
生成一个文件,内容是一棵二叉树的层次遍历
void printBinaryTree(const binaryTree< T, Comparator > &bin_tree, const typename binaryTree< T, Comparator >::value_type &flag, std::ostream &out=std::cout)
输出一棵二叉树