Recursive Implementation of full string Arrangement

Source: Internet
Author: User

Recursive Implementation of full string Arrangement

# Include "stdafx. h" # include

  
   
# Include using namespace std; void permutation (char * pStr, char * pBegin) {assert (pStr & pBegin); if (* pBegin = '\ 0 ') cout <pStr <endl; else {for (char * pCh = pBegin; * pCh! = '\ 0'; ++ pCh) {swap (* pBegin, * pCh); permutation (pStr, pBegin + 1); swap (* pBegin, * pCh) ;}} int main () {char str [] = "abcd"; permutation (str, str );}

  
This operation is performed on the source string. Therefore, SwapAnd then you need to try again SwapBack to restore. The final result is grouped.
To AStarts BStarts CStarts DStart with, followed by three characters
First place a characterAAfter switching with the next character, you only need to recursively call the current function for the next three characters.. The recursion condition is that the string is empty. * PBegin = '\ 0'.

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.