Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- template <class smth>
- bool my_next_permutation(smth first, smth last)
- {
- smth end = last;
- end--;
- cout << "проверка концов" << *first << ' ' << *end << "\n";
- if (first == end) return 0;
- smth runner = end;
- cout << *runner << "присвоил бегунок" <<"\n";
- if (first == --runner) return 0;
- smth right, left;
- left = end;
- cout << *left <<"присвоил левый" << "\n";
- //runner--;
- cout << *runner << "проверка бегунка перед поиском опорной точки" <<'\n';
- while ((*runner > * left)) //&& (runner > first))
- {
- cout << *runner <<"бегунок внутри"<< '\n';
- cout << *left << "левый внутри" << '\n';
- cout << *first << "первый внутри" << "\n";
- if (runner == first)
- {
- cout << *first /*<< *last */<< "runner == first" << '\n';
- return 0;
- }
- runner--;
- left--;
- }
- cout << *runner << "проверка бегунка ПОСЛЕ поиска опорной точки" << '\n';
- cout << *left << "левый ПОСЛЕ поиска" << "\n";
- right = end;
- cout << *right << "проверка создания" << '\n';
- while ((*right < *runner) && (right > left))
- {
- right--;
- cout << *right << "проверка создания внутри" << '\n';
- }
- cout << *right << "проверк после создания" << "\n";
- cout << *runner << "проверка ПОСЛЕ бегунка" << "\n";
- if (runner != right) iter_swap(runner, right);
- sort(left, last);
- return 1;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- ofstream out("track_list.txt");
- vector <int> vec{ 1, 2, 3};
- do
- {
- for (int i = 0; i < vec.size(); i++)
- {
- cout << vec[i];
- out << vec[i];
- }
- cout << '\n';
- out << '\n';
- } while (my_next_permutation(vec.begin(), vec.end()));
- //while (next_permutation(vec.begin(), vec.end()));
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement