Complete arrangement of C ++ code (3)
# Include <assert. h >#include <iostream >#include <algorithm> using namespace STD; Template <typename T> void perm (T * PT, int N, int m) {If (n = m) {for (INT I = 0; I <m; I ++) cout <PT [I] <""; cout <Endl; return;} else {for (INT I = m; I <n; I ++) {swap (PT [m], PT [I]); perm (PT, n, m + 1); swap (PT [m], PT [I]) ;}} class permutation {public: Enum {max_size = 10 }; permutation (INT count) {assert (0 <count & count <max_size); m_ncount = (char) count; For (char I = 0; I <m_ncount; I ++) m_indexs [I] = I;} public: bool tonext (); char operator [] (INT N) const {assert (0 <= N & n <= m_ncount ); return m_indexs [N];} PRIVATE: Char m_indexs [max_size]; char m_ncount;}; bool permutation: tonext () {char nreverse = m_nCount-1; while (nreverse> 0 & m_indexs [nreverse] <m_indexs [nReverse-1]) nreverse --; // find the first element to be swapped if (nreverse = 0) // cannot be found, indicating that the full row has been returned false; char nswap = m_ncount-1; while (m_indexs [nswap] <m_indexs [nReverse-1]) nswap --; // find the second element swap (m_indexs [nReverse-1], m_indexs [nswap]); // start switching reverse (m_indexs + nreverse, m_indexs + m_ncount ); // return true;} int main () {const int n = 3; permutation perm (n); const char * stests [N] = {"AAA ", "BBB", "CCC"}; do {for (INT I = 0; I <n; I ++) cout <stests [perm [I] <""; cout <Endl;} while (perm. tonext (); Return 0 ;}