Arrangement of characters

Source: Internet
Author: User

Issue: Enter a string (requires no duplicate characters) to print out all permutations of characters in the character string.

Idea: Ask for all characters that may appear in the first position, swapping the first character with the character one by one after it. The first character is fixed, and all subsequent characters are arranged. This time throw all the following characters into two parts: the first character of the following character, and all the characters after the character, and then exchange the first character one after the other with the characters that follow it.

1#include <stdio.h>2#include"stdafx.h"3#include <tchar.h>4 5 voidPermutation (Char* PStr,Char*pbegin);6 7 voidPermutation (Char*pStr)8 {9     if(PStr = =NULL)Ten         return; One  A permutation (pStr, pStr); - } -  the voidPermutation (Char* PStr,Char*pbegin) - { -     if(*pbegin = =' /') -     { +printf"%s\n", pStr); -     } +     Else A     { at          for(Char* PCh = Pbegin; *pch! =' /'; ++pCh) -         { -             Chartemp = *pCh; -*pch = *Pbegin; -*pbegin =temp; -  inPermutation (pStr, Pbegin +1); -  totemp = *pCh; +*pch = *Pbegin; -*pbegin =temp; the         } *     } $ }Panax Notoginseng  - intMain () the { +  A     Char string[] ="ABC"; thePermutation (string); +      -     return 0; $}

Arrangement of characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.