Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include "sleepsort.hpp"
  2.  
  3. #include <twist/stdlike/thread.hpp>
  4.  
  5. #include <twist/support/compiler.hpp>
  6.  
  7. #include <chrono>
  8.  
  9. // Acts like std::thread
  10. using twist::thread;
  11.  
  12. using twist::this_thread::sleep_for;
  13.  
  14. namespace solutions {
  15.  
  16. void SleepSort(std::vector<int>& ints) {
  17.   // Use 'thread' class to launch/join threads
  18.  
  19.   // Use 'sleep_for' function to sleep
  20.   // E.g. sleep_for(std::chrono::microseconds(42));
  21.  
  22.   // Your code goes here
  23.   std::vector<std::thread> thread_array_;
  24.   size_t start_size_ = ints.size();
  25.   for (size_t i = 0; i < start_size_; ++i) {
  26.     int new_value_ = ints.front();
  27.     ints.erase(ints.begin(), ints.begin() + 1);
  28.    
  29.     thread_array_.push_back(std::thread ( [&ints, new_value_] () { std::chrono::microseconds(new_value_); ints.push_back(new_value_); } ) );
  30.   }
  31.   UNUSED(ints);
  32. }
  33.  
  34. }  // namespace solutions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement