33 static bool GenTreeData(
const char *_file_path =
"./test0.txt",
const char *empty_flag =
"@");
45 template <
typename T,
typename Comparator>
48 int main(
int argc,
char const *argv[])
56 timeinfo = localtime(&rawtime);
59 const std::string full_path_exec{argv[0]};
60 std::string::size_type found = full_path_exec.find_last_of(
"/\\", std::string::npos);
61 const std::string exec_path = full_path_exec.substr(0, found + 1);
62 const std::string exec_filename = full_path_exec.substr(found + 1, std::string::npos);
71 std::cout <<
"文件:" << data_file_full_path <<
"生成失败!\n";
76 std::ifstream fin(data_file_full_path.c_str(), std::ios_base::in);
79 std::cout <<
"文件:" << data_file_full_path <<
"读取失败!\n";
89 std::ofstream fout(data_file_full_path.c_str(), std::ios_base::app);
92 std::cerr <<
"文件:" << data_file_full_path <<
"写入失败!\n";
97 std::cout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
98 fout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
104 binary_tree.swaplr();
105 std::cout <<
"\n交换左右结点后:\n";
106 fout <<
"\n交换左右结点后:\n";
112 std::cout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
113 fout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
122 std::string file_path(_file_path);
125 std::string cmd = std::string(
"DEL /P \"") + file_path +
'"';
127 system(
"echo We are trying to delete some files, which will be created later.");
132 std::ifstream fin(file_path.c_str(), std::ios_base::in);
135 std::cerr <<
"文件已存在!\n";
143 std::ofstream fout(file_path.c_str(), std::ios_base::out);
146 std::cerr <<
"无写权限,文件生成失败!\n";
153 <<
"B\tE\t" << empty_flag <<
"\tD\n"
154 << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' << empty_flag <<
'\t' <<
"W\t" << empty_flag <<
'\n'
155 << empty_flag <<
"\tX\n"
156 << empty_flag <<
'\t' << empty_flag << std::endl;
161 system(
"echo File created successfully!");
167 std::cerr <<
"无法生成文件!\n";
172 template <
class T,
typename Comparator>
175 out <<
"二叉树的规模(递归 非递归):\n"
177 out <<
"\n二叉树的高(深)度(递归 非递归),从0起:\n"
180 out <<
"\n度为2的结点的个数是:\n"
182 out <<
"\n前序遍历(递归):\n";
184 out <<
"\n前序遍历(非递归):\n";
186 out <<
"\n中序遍历(递归):\n";
188 out <<
"\n中序遍历(非递归):\n";
190 out <<
"\n后序遍历(递归):\n";
192 out <<
"\n后序遍历(非递归):\n";
196 out <<
"\n层次打印(调用lchild(), rchild(), root()等API):\n";