C++ simple implementation of the full array algorithm example

  • 2020-05-26 09:46:00
  • OfStack

The example of this article describes a simple implementation of C++ full permutation algorithm. I will share it with you for your reference as follows:


#include "stdafx.h"
#include <string>
#include <algorithm>
#include <iostream>
void func(const char *str_in)
{
  std::string str(str_in);
  std::sort(str.begin(),str.end());
  do
  {
    std::cout<<str<<std::endl;
  }while (std::next_permutation(str.begin(),str.end()));
}
int _tmain(int argc, _TCHAR* argv[])
{
  func("cab");
  return 0;
}

I hope this article is helpful to you C++ programming.


Related articles: