Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- int counter;
- void quick_sort(std::vector<int> arr, int S, int E) {
- int i = S, j = E;
- int pivotal = arr[(S + E) / 2];
- while(i <= j) {
- while(arr[i] < pivotal) {
- counter++;
- i++;
- }
- while(arr[j] > pivotal) {
- counter++;
- j--;
- }
- if(i <= j) {
- counter++;
- std::swap(arr[i], arr[j]);
- i++;
- j--;
- }
- counter++;
- }
- if(S < j) {
- counter++;
- quick_sort(arr, S, j);
- }
- if(i < E) {
- counter++;
- quick_sort(arr, i, E);
- }
- }
- int main()
- {
- std::ios_base::sync_with_stdio(0);
- // 1, 2, 3, 4, 5, 6, 7
- // 5, 4, 3, 2, 1, 6, 7
- std::vector<int> v{1, 2, 3, 4 ,5 ,6, 7};
- int maks= 0;
- do{
- counter = 0;
- std::vector<int> v2 = v;
- quick_sort(v2, 0, 6);
- if(counter == 37) {
- for(int j = 0; j < 7; j++) {
- std::cout << v[j] << " ";
- }
- std::cout << std::endl;
- }
- }while(std::next_permutation(v.begin(), v.end()));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement