36 static bool GenTreeData(
const char *_file_path =
"./test0.txt",
const char *empty_flag =
"@");
48 template <
typename T,
typename Comparator>
51 int main(
int argc,
char const *argv[])
59 timeinfo = localtime(&rawtime);
62 const std::string full_path_exec{argv[0]};
63 std::string::size_type found = full_path_exec.find_last_of(
"/\\", std::string::npos);
64 const std::string exec_path = full_path_exec.substr(0, found + 1);
65 const std::string exec_filename = full_path_exec.substr(found + 1, std::string::npos);
73 std::cout <<
"文件:" << data_file_full_path <<
"生成失败!\n";
78 std::ifstream fin(data_file_full_path.c_str(), std::ios_base::in);
81 std::cout <<
"文件:" << data_file_full_path <<
"读取失败!\n";
91 std::ofstream fout(data_file_full_path.c_str(), std::ios_base::app);
94 std::cerr <<
"文件:" << data_file_full_path <<
"写入失败!\n";
99 std::cout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
100 fout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
106 binary_tree.swaplr();
107 std::cout <<
"\n交换左右结点后:\n";
108 fout <<
"\n交换左右结点后:\n";
113 binary_tree.delLeft(
"G");
114 binary_tree.delRight(
"G");
115 std::cout <<
"\n剪枝后:\n";
122 std::cout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
123 fout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
132 std::string file_path(_file_path);
135 std::string cmd = std::string(
"DEL /P \"") + file_path +
'"';
137 system(
"echo We are trying to delete some files, which will be created later.");
142 std::ifstream fin(file_path.c_str(), std::ios_base::in);
145 std::cerr <<
"文件已存在!\n";
153 std::ofstream fout(file_path.c_str(), std::ios_base::out);
156 std::cerr <<
"无写权限,文件生成失败!\n";
164 << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' <<
"H\tI\n"
165 << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag << std::endl;
170 system(
"echo File created successfully!");
176 std::cerr <<
"无法生成文件!\n";
181 template <
class T,
typename Comparator>
184 out <<
"二叉树的规模(递归 非递归):\n"
186 out <<
"\n二叉树的高(深)度(递归 非递归),从0起:\n"
189 out <<
"\n度为2的结点的个数是:\n"
192 out <<
"\n是否为满二叉树:\n"
195 out <<
"\n是否为完全二叉树:\n"
197 out <<
"\n前序遍历(递归):\n";
199 out <<
"\n前序遍历(非递归):\n";
201 out <<
"\n中序遍历(递归):\n";
203 out <<
"\n中序遍历(非递归):\n";
205 out <<
"\n后序遍历(递归):\n";
207 out <<
"\n后序遍历(非递归):\n";
211 out <<
"\n层次打印(调用lchild(), rchild(), root()等API):\n";