• 剑指Offer26 字符串的全排列


     1 /*************************************************************************
     2     > File Name: 26_StringPermutation.cpp
     3     > Author: Juntaran
     4     > Mail: JuntaranMail@gmail.com
     5     > Created Time: 2016年08月31日 星期三 16时11分13秒
     6  ************************************************************************/
     7 
     8 #include <stdio.h>
     9 
    10 void Permutation(char* str, char* begin)
    11 {
    12     if (*begin == '')
    13         printf("%s
    ", str);
    14     else
    15     {
    16         for (char* left = begin; *left != ''; left++)
    17         {
    18             // left与begin交换值
    19             char temp = *left;
    20             *left = *begin;
    21             *begin = temp;
    22             
    23             Permutation(str, begin+1);
    24             
    25             temp = *left;
    26             *left = *begin;
    27             *begin =temp;
    28         }
    29     }
    30 }
    31 
    32 // 字符串的全排列
    33 void Permutation(char* str)
    34 {
    35     if (str == NULL)
    36         return;
    37     Permutation(str, str);
    38 }
    39 
    40 int main()
    41 {
    42     char str[] = "abc";
    43     Permutation(str);
    44     
    45     return 0;
    46 }
  • 相关阅读:
    消息队列设计
    抓包工具Fiddler
    分布式系统和CAP
    Topshelf组件
    Parallel.For
    MVC插件
    Azure Messaging-ServiceBus Messaging
    MVC
    requireJS
    第一次react-native项目实践要点总结 good
  • 原文地址:https://www.cnblogs.com/Juntaran/p/5826591.html
Copyright © 2020-2023  润新知