将一组数据从小到大排序。。。。
嗯。。。。
对。。。
就是排序。。。
好了,直接上代码。。。
#include <iostream>
#include <thread>
#include <vector>
#include <chrono>
void sleepSort(int num)
{
std::this_thread::sleep_for(std::chrono::milliseconds(num * 100));
std::cout << num << " ";
}
int main() {
std::vector<int> arr = { 5, 3, 8, 4, 2 };
std::vector<std::thread> threads;
for (int num : arr) {
threads.emplace_back(sleepSort, num);
}
for (std::thread& t : threads) {
t.join();
}
std::cout << std::endl;
return 0;
}
结果显示: