全排列的两种实现

#include <stdio.h>

bool used[MAX_N];
int perm[MAX_N];

int main()
{

    return 0;
}

//next_permutation_without_stl
void permutaion1(int pos, int n)
{
    if (pos == n)
    {

        return;
    }

    for (i = 0; i < n; i++)
    {
        if (!used[i])
        {
            perm[pos] = i;
            used[i] = true;
            permutaion1(pos + 1, n);
            used[i] = false;
        }
    }
    return;
}

#include <algorithm>
using namespace std;

int perm2[MAX_N];

//next_permutation_with_stl
void permutaion2(int n)
{
    for (i = 0; i < n; i++)
    {
        perm2[i] = i;
    }

    do
    {

    }
    while(next_permutation(perm2, perm2 + n));

    return;
}
添加新评论