c++11 的睡觉排序法

之前在网上看到了一个叫做睡觉排序法,大部分是用java实现的

现在我用c++实现一下

void sleepSortHelper(int i) {
    this_thread::sleep_for(chrono::microseconds(i*10000));
    std::cout << i << " ";
}
void sleepSort(int *arr,int size) {

    for (int i = 0; i < size; i++)
    {
        std::thread t(sleepSortHelper,arr[i]);
        t.detach();
    }

}
void main() {

    sleepSort(arr, 7);
    getchar();
}

记住要添加头文件

#include<thread>

 

posted @ 2018-12-17 11:37  zezezeze  阅读(761)  评论(0)    收藏  举报