zoukankan      html  css  js  c++  java
  • 【算法1】string 的全排列

    void Permutation(char* pStr, char* pBegin);
    
    /////////////////////////////////////////////////////////////////////////
    // Get the permutation of a string, 
    // for example, input string abc, its permutation is 
    // abc acb bac bca cba cab
    /////////////////////////////////////////////////////////////////////////
    void Permutation(char* pStr)
    {
          Permutation(pStr, pStr);
    }
    
    /////////////////////////////////////////////////////////////////////////
    // Print the permutation of a string, 
    // Input: pStr   - input string
    //        pBegin - points to the begin char of string 
    //                 which we want to permutate in this recursion
    /////////////////////////////////////////////////////////////////////////
    void Permutation(char* pStr, char* pBegin)
    {
          if(!pStr || !pBegin)
                return;
    
          // if pBegin points to the end of string,
          // this round of permutation is finished, 
          // print the permuted string
          if(*pBegin == '0')
          {
                printf("%s
    ", pStr);
          }
          // otherwise, permute string
          else
          {
                for(char* pCh = pBegin; *pCh != '0'; ++ pCh)
                {
                      // swap pCh and pBegin
                      char temp = *pCh;
                      *pCh = *pBegin;
                      *pBegin = temp;
    
                      Permutation(pStr, pBegin + 1);
    
                      // restore pCh and pBegin
                      temp = *pCh;
                      *pCh = *pBegin;
                      *pBegin = temp;
                }
          }
    }
  • 相关阅读:
    python 根据数组生成图片
    c++ 字符串转数字
    python 迷宫问题
    JavaScript 判断是否为空
    JavaScript 字符串转数字(整数,浮点数,进制转换)
    c++ 珊格迷宫问题
    python eval的用法
    python pillow 处理图片
    c 结构体
    python pillow 绘制图片
  • 原文地址:https://www.cnblogs.com/ymecho/p/3308073.html
Copyright © 2011-2022 走看看