| 202 | } |
| 203 | |
| 204 | int main() { |
| 205 | // vector<int> data = {5, 2, 9, 1, 5, 6, 10, 3, 8, 7}; |
| 206 | vector<int> data = generateRandomData(10720); |
| 207 | vector<int> data2 = data; |
| 208 | |
| 209 | int n = data.size(); |
| 210 | int k = 6; // 设置迭代次数 |
| 211 | |
| 212 | //Shuffle the values of data |
| 213 | random_shuffle(data.begin(), data.end()); |
| 214 | |
| 215 | int number = 0; |
| 216 | auto start = chrono::high_resolution_clock::now(); |
| 217 | modified_aav86_max(data, k, &number); |
| 218 | auto end = chrono::high_resolution_clock::now(); |
| 219 | auto duration = chrono::duration_cast<chrono::milliseconds>(end - start); |
| 220 | cout << "Time taken for finding max: " << duration.count() << " milliseconds" << endl; |
| 221 | cout << "max value: " << data.back() << endl; |
| 222 | cout << "compare number: " << number << endl; |
| 223 | |
| 224 | start = chrono::high_resolution_clock::now(); |
| 225 | auto max_value = std::max_element(data.begin(), data.end()); |
| 226 | end = chrono::high_resolution_clock::now(); |
| 227 | duration = chrono::duration_cast<chrono::milliseconds>(end - start); |
| 228 | cout << "Time taken for finding max: " << duration.count() << " milliseconds" << endl; |
| 229 | cout << "Maximum value: " << *max_value << endl; |
| 230 | |
| 231 | // 测试快速选择的TopK实现 |
| 232 | // vector<int> data_quickselect = generateRandomData(30720); |
| 233 | int topk = 1; // 要找前100个最大值 |
| 234 | number = 0; |
| 235 | |
| 236 | start = chrono::high_resolution_clock::now(); |
| 237 | vector<int> result = quick_select_topk(data2, topk, &number); |
| 238 | end = chrono::high_resolution_clock::now(); |
| 239 | duration = chrono::duration_cast<chrono::milliseconds>(end - start); |
| 240 | |
| 241 | cout << "\nQuick Select Top " << topk << " values:" << endl; |
| 242 | for (int i = 0; i < min(topk, (int)result.size()); ++i) { |
| 243 | cout << result[i] << " "; |
| 244 | } |
| 245 | cout << "\nTime taken for finding top " << topk << ": " |
| 246 | << duration.count() << " milliseconds" << endl; |
| 247 | cout << "Compare number: " << number << endl; |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | // ... existing code ... |
| 253 |
nothing calls this directly
no test coverage detected