3. provides all the arrays of the output strings of a function.

Source: Internet
Author: User

/*************************************** *********************************/
/* 3. All the arrays of the output strings of a function */
/*************************************** *********************************/
Template <typename T>
Void printvect (vector <t> & S)
{
Typename vector <t >:: iterator beg = S. Begin ();
While (beg! = S. End ())
Cout <* beg ++;
Cout <Endl;
}
Void arrangementrecursive (char * STR, vector <char> & cvect)
{
If (* STR = '\ 0 ')
{
// Print the result
Printvect (cvect );
Return;
}
Int length = strlen (STR );
// Function Change STR, use tempstr, and restore after recursion. At the same time, ensure that the access to showarrangement ("ABC") is not out of bounds.
Char * tempstr = new char [Length + 1];
For (INT I = 0; I <length; ++ I)
{
Strcpy_s (tempstr, Length + 1, STR );
// Exchange the first element with the following element
Swap (tempstr [I], tempstr [0]);
// Stack entry
Cvect. push_back (tempstr [0]);
// All n-1 elements are arranged
Arrangementrecursive (tempstr + 1, cvect );
// The sorting starting with * STR is completed, and the output stack is
Cvect. pop_back ();
}
Delete [] tempstr;
}
Void showarrangement (char * Str)
{
If (! Str)
Return;
// Cvect Save the order to be printed
Vector <char> cvect;
Arrangementrecursive (STR, cvect );
}

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.