Advertisement
Guest User

Untitled

a guest
Mar 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <thread>
  2. #include <iostream>
  3. #include <vector>
  4. #include <numeric>
  5. #include <fstream>
  6. std::ofstream plik_wyj("plik.txt");
  7. bool odnaleziono = false;
  8.  
  9. void search_tab(const std::vector<int> &tab, int poc, int kon, int szuk)
  10. {
  11.  
  12.  
  13.         for (int i = poc; i < kon; i++)
  14.         {
  15.             if (odnaleziono == true)
  16.             {
  17.                 break;
  18.             }
  19.             if (tab[i] == szuk)
  20.             {
  21.                 plik_wyj << "odnaleziono" << std::endl;
  22.                 odnaleziono = true;
  23.                 break;
  24.             }
  25.         }
  26.    
  27. }
  28.  
  29. int main()
  30. {
  31.     std::vector<int> tab(200);
  32.     std::iota(tab.begin(), tab.end(), 1);
  33.     int x = 0;
  34.     for (int i = 0, j = 25; i < 200; i += 25, j += 25)
  35.     {
  36.         std::thread th(&search_tab, tab, i,j,100);
  37.         plik_wyj << "TH: " << th.get_id() << std::endl;
  38.         th.detach();
  39.     }
  40.     if (odnaleziono == false)
  41.         plik_wyj << "nie odnaleziono";
  42.  
  43.     std::cin.ignore(20);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement