70 int main(
int argc,
char const *argv[])
78 const std::string full_path_exec{argv[0]};
79 std::string::size_type found = full_path_exec.find_last_of(
"/\\", std::string::npos);
80 const std::string exec_path = full_path_exec.substr(0, found);
81 const std::string exec_filename = full_path_exec.substr(found + 1, std::string::npos);
82 const std::string data_file_name(
"\\ch7_7.result");
85 std::string data_file_full_path{exec_path + data_file_name};
86 std::ofstream fout(data_file_full_path.c_str(), std::ios_base::app);
89 std::cerr <<
"无写权限,测试数据文件生成失败!\n";
97 timeinfo = localtime(&rawtime);
99 std::cout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
100 fout <<
"\nCurrent local time and date: " << asctime(timeinfo) <<
'\n';
105 int low{10}, high{99}, num_of_points{18};
112 for (
int i = 0; i < num_of_points; ++i)
114 iSecret = low + (high - low + 1) * rand() / (RAND_MAX + 1);
127 for (
size_t i = 0; i < priority_queue.
size(); ++i)
129 iSecret = low + (high - low + 1) * rand() / (RAND_MAX + 1);
130 std::cout <<
"findMin(" << iSecret <<
") = " << priority_queue.
findMin(iSecret) <<
'\n';
131 fout <<
"findMin(" << iSecret <<
") = " << priority_queue.
findMin(iSecret) <<
'\n';
135 for (
int i = 1; i <= num_of_points; ++i)
137 iSecret = -low + (high + low + 1) * rand() / (RAND_MAX + 1);
140 std::cout <<
"\n全部结点加减随机数后: " << priority_queue <<
'\n';
141 fout <<
"\n全部结点加减随机数后: " << priority_queue <<
'\n';
144 std::cout <<
"\n依次出队: \n";
145 fout <<
"\n依次出队: \n";
146 for (
int i = 0; i < num_of_points; ++i)
148 auto obj = priority_queue.
top();
149 priority_queue.pop();
150 std::cout << obj <<
", ";
154 catch (
const std::string &e)
156 std::cerr << e <<
'\n';
163 std::cout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
164 fout <<
"\nIt took me " << t <<
" clicks (" << ((float)t) / CLOCKS_PER_SEC <<
" seconds).\n";
175 int current_min{INT_MAX};
180 current_min =
array_[current_index = i];
184 return current_index;
192 array_[i] = array_[i] - value;
201 decreaseKey(i, -value);