Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sleepsort.hpp"
- #include <twist/stdlike/thread.hpp>
- #include <twist/support/compiler.hpp>
- #include <chrono>
- // Acts like std::thread
- using twist::thread;
- using twist::this_thread::sleep_for;
- namespace solutions {
- void SleepSort(std::vector<int>& ints) {
- // Use 'thread' class to launch/join threads
- // Use 'sleep_for' function to sleep
- // E.g. sleep_for(std::chrono::microseconds(42));
- // Your code goes here
- std::vector<std::thread> thread_array_;
- size_t start_size_ = ints.size();
- for (size_t i = 0; i < start_size_; ++i) {
- int new_value_ = ints.front();
- ints.erase(ints.begin(), ints.begin() + 1);
- thread_array_.push_back(std::thread ( [&ints, new_value_] () { std::chrono::microseconds(new_value_); ints.push_back(new_value_); } ) );
- }
- UNUSED(ints);
- }
- } // namespace solutions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement