相关疑难解决方法(0)

std :: next_permutation实现说明

我很好奇如何std:next_permutation实现,所以我提取了gnu libstdc++ 4.7版本并清理了标识符和格式以生成以下演示...

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

template<typename It>
bool next_permutation(It begin, It end)
{
        if (begin == end)
                return false;

        It i = begin;
        ++i;
        if (i == end)
                return false;

        i = end;
        --i;

        while (true)
        {
                It j = i;
                --i;

                if (*i < *j)
                {
                        It k = end;

                        while (!(*i < *--k))
                                /* pass */;

                        iter_swap(i, k);
                        reverse(j, end);
                        return true;
                }

                if (i == begin) …
Run Code Online (Sandbox Code Playgroud)

c++ permutation lexicographic stl-algorithm c++11

100
推荐指数
4
解决办法
3万
查看次数

标签 统计

c++ ×1

c++11 ×1

lexicographic ×1

permutation ×1

stl-algorithm ×1