28 int main(
int argc,
char const *argv[])
36 const std::string full_path_exec{argv[0]};
37 std::string::size_type found = full_path_exec.find_last_of(
"/\\", std::string::npos);
38 const std::string exec_path = full_path_exec.substr(0, found);
39 const std::string exec_filename = full_path_exec.substr(found + 1, std::string::npos);
40 const std::string data_file_name(
"\\ch7_1.result");
43 std::string data_file_full_path{exec_path + data_file_name};
44 std::ofstream fout(data_file_full_path.c_str(), std::ios_base::app);
47 std::cerr <<
"无写权限,测试数据文件生成失败!\n";
55 timeinfo = localtime(&rawtime);
57 std::cout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
58 fout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
63 int low{10}, high{99}, num_of_points{18};
70 for (
int i = 0; i < num_of_points; ++i)
72 iSecret = low + (high - low + 1) * rand() / (RAND_MAX + 1);
73 string_array.
push_back(std::to_string(iSecret));
84 while (!priority_queue.empty())
86 str = priority_queue.
top();
87 priority_queue.pop(&str);
88 std::cout << str <<
", ";
93 << std::boolalpha << priority_queue.empty() <<
'\n';
95 << std::boolalpha << priority_queue.empty() <<
'\n';
98 for (
int i = 0; i < num_of_points; ++i)
100 priority_queue.push(string_array[i]);
104 while (!priority_queue.empty())
106 str = priority_queue.top();
107 priority_queue.pop(&str);
108 std::cout << str <<
", ";
112 catch (
const std::string &e)
114 std::cerr << e <<
'\n';
121 std::cout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
122 fout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";