Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. template <class smth>
  12. bool my_next_permutation(smth first, smth last)
  13. {
  14.     smth end = last;
  15.     end--;
  16.     cout << "проверка концов" << *first << ' ' << *end << "\n";
  17.     if (first == end)  return 0;
  18.     smth runner = end;
  19.     cout << *runner << "присвоил бегунок" <<"\n";
  20.     if (first == --runner)  return 0;
  21.  
  22.     smth right, left;
  23.  
  24.     left = end;
  25.     cout << *left <<"присвоил левый" << "\n";
  26.     //runner--;
  27.  
  28.     cout << *runner << "проверка бегунка перед поиском опорной точки" <<'\n';
  29.     while ((*runner > * left)) //&& (runner > first))
  30.     {
  31.         cout << *runner <<"бегунок внутри"<< '\n';
  32.         cout << *left << "левый внутри" << '\n';
  33.         cout << *first << "первый внутри" << "\n";
  34.         if (runner == first)
  35.         {
  36.             cout << *first /*<< *last */<< "runner == first" << '\n';
  37.             return 0;
  38.         }
  39.  
  40.         runner--;
  41.         left--;
  42.     }
  43.     cout << *runner << "проверка бегунка ПОСЛЕ поиска опорной точки" << '\n';
  44.    
  45.     cout << *left << "левый ПОСЛЕ поиска" << "\n";
  46.     right = end;
  47.     cout << *right << "проверка создания" << '\n';
  48.     while ((*right < *runner) && (right > left))
  49.     {
  50.         right--;
  51.         cout << *right << "проверка создания внутри" << '\n';    
  52.     }
  53.     cout << *right << "проверк после создания" << "\n";
  54.     cout << *runner << "проверка ПОСЛЕ бегунка" << "\n";
  55.     if (runner != right) iter_swap(runner, right);
  56.     sort(left, last);
  57.     return 1;
  58. }
  59.  
  60. int main()
  61. {
  62.     setlocale(LC_ALL, "Russian");
  63.     ofstream out("track_list.txt");
  64.     vector <int> vec{ 1, 2, 3};
  65.  
  66.     do
  67.     {
  68.         for (int i = 0; i < vec.size(); i++)
  69.         {
  70.             cout << vec[i];
  71.             out << vec[i];
  72.         }
  73.         cout << '\n';
  74.         out << '\n';
  75.     } while (my_next_permutation(vec.begin(), vec.end()));
  76.     //while (next_permutation(vec.begin(), vec.end()));
  77.     out.close();
  78.     return 0;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement