zoukankan      html  css  js  c++  java
  • JZ-C-28

     剑指offer第二十八题:字符串的排列

     1 //============================================================================
     2 // Name        : JZ-C-28.cpp
     3 // Author      : Laughing_Lz
     4 // Version     :
     5 // Copyright   : All Right Reserved
     6 // Description : 字符串的排列
     7 //============================================================================
     8 
     9 #include <iostream>
    10 #include <stdio.h>
    11 using namespace std;
    12 
    13 void Permutation(char* pStr, char* pBegin);
    14 void Permutation(char* pStr) {
    15     if (pStr == NULL) {
    16         return;
    17     }
    18     Permutation(pStr, pStr);
    19 }
    20 void Permutation(char* pStr, char* pBegin) {
    21     if (*pBegin == '') {
    22         printf("%s
    ", pStr);
    23     } else {
    24         for (char* pCh = pBegin; *pCh != ''; pCh++) {
    25             char temp = *pBegin;
    26             *pBegin = *pCh;
    27             *pCh = temp;
    28 
    29             Permutation(pStr, pBegin + 1);
    30 
    31             temp = *pBegin;
    32             *pBegin = *pCh;
    33             *pCh = temp;
    34         }
    35     }
    36 
    37 }
    38 // ====================测试代码====================
    39 void Test(char* pStr) {
    40     if (pStr == NULL)
    41         printf("Test for NULL begins:
    ");
    42     else
    43         printf("Test for %s begins:
    ", pStr);
    44 
    45     Permutation(pStr);
    46 
    47     printf("
    ");
    48 }
    49 
    50 int main(int argc, char** argv) {
    51     Test(NULL);
    52 
    53     char string1[] = "";
    54     Test(string1);
    55 
    56     char string2[] = "a";
    57     Test(string2);
    58 
    59     char string3[] = "ab";
    60     Test(string3);
    61 
    62     char string4[] = "abc";
    63     Test(string4);
    64 
    65     return 0;
    66 }
  • 相关阅读:
    表连接问题
    public interface Serializable?标记/标签接口
    4.21
    第十周周记
    测试
    第九周周记
    第七周周记
    fighting.
    fighting
    作业一
  • 原文地址:https://www.cnblogs.com/Laughing-Lz/p/5592246.html
Copyright © 2011-2022 走看看