IT&컴퓨터공학/자료구조&알고리즘

[알고리즘] 순열 알고리즘 - C++ 구현

yan_z 2021. 1. 10. 18:46
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;



/* 순열 알고리즘 */
void Permutation(vector<int>& Array, int Start, int End)
{
    if (Start == End)
    {
        for (const auto it : Array)
        {
            cout << it << " ";
        }
        cout << endl;


    }
    else
    {
        for (int i = Start; i <= End; ++i)
        {
            swap(Array[Start], Array[i]);
            Permutation(Array, Start + 1, End);
            swap(Array[Start], Array[i]);
        }
    }
}