This article describes the C language implementation of the input of a string to print out the character in the string of all permutations of the method, which belongs to the mathematical arrangement problem. is a very practical algorithm technique. Share to everyone for your reference. The implementation methods are as follows:
For example, the input string, ABC, outputs all the strings that can be arranged by character A, b, and C, ABC, ACB, BAC, BCA, Cab, and CBA.
The C language implementation code is as follows:
/* Copyright (c) alexingcool. All Rights Reserved.
* *
#include <iostream>
#include <algorithm>
using namespace std;
Char array[] = {' A ', ' B ', ' C '};
const int size = sizeof array/sizeof *array;
void Perm (char *array, int pos, int last)
{
if (pos = last) {
copy (array, array + size, ostream_iterator< ;char> (cout, ""));
cout << Endl;
}
else {
for (int i = pos; I <= last; i++) {
swap (array[i], Array[pos]);
Perm (Array, pos + 1, last);
Swap (Array[i], Array[pos]);
}} void Main ()
{
Perm (array, 0, 2);
}
It is hoped that the examples mentioned in this paper will be helpful to the learning of C program algorithm design.