Simple implementation of all-altered generic algorithms

xiaoxiao2021-03-06  70

The following is a simple implementation of a full-aligned generic algorithm; I use it to generate test sequences to be used for some code testing; By the way, the generic algorithm is studied; the implementation is still more primitive, and it still needs to be improved; #pragma Warning (Disable : 4530) #pragma Warning (Disable: 4786) #include #include #include #include #include #include using namespace std;

// Main, no detection overflow unsigned __int64 _tfactorial (unsigned __int64 n) {unsigned __int64 r = 1; for (unsigned __int64 i = 2; i <= n; i ) r * = i; return r;}

// Run, do not detect repetition template Void Arrange (t * first, t * last, array matrix, int rot, int co = 0) {if (first> = last) return;

INT N = Last - First;

IF (n == 1) // Remissive termination {Matrix [ROW] [col] = * first; return;} int line_n = _tfactorial (n - 1); t * temp = new T [n - 1], * CP ;

For (int i = 0, j; i

For (cp = temp, j = 0; j

Arrange (TEMP, TEMP N - 1, Matrix, Row i * line_n, col 1);

DELETE [] TEMP;

INT Main (int Argc, char * argv []) {Try {Int i, j;

CHAR C [5] = "1234"; // Waiting for data char RC [24] [4]; // Save results

String Str [3] = {"The", "if", "else"}; string rstr [6] [3];

Arrange (C, C 4, RC); for (i = 0; i <24; i ) {for (j = 0; j <4; j ) cout << rc [i] [J] << ','; cout << endl;

Arrange (STR, STR 3, RSTR); for (i = 0; i <6; i ) {for (j = 0; j <3; j ) cout << rstr [i] [J] << ','; cout << endl;} // STL container char vc [] = "abcd"; vector vec (vc, vc 4); vector > rVEC; / / Do not use containers to return parameters arrange (vec.begin (), vec.end (), rc); for (i = 0; i <24; i ) {for (j = 0; J <4; j ) cout << RC [i] [j] << ','; cout << end1;}} catch (exception & e) {cout << E.What () << endl;} return }

---------- Results -------- 1, 2, 3, 4, 1, 2, 4, 3, 1, 3, 2, 4, 1, 3, 4 2, 1, 4, 2, 3, 1, 4, 3, 2, 2, 1, 3, 4, 2, 1, 4, 3, 2, 3, 1, 4, 2, 3, 4, 1 2, 4, 1, 3, 2, 4, 3, 1, 3, 1, 2, 4, 3, 1, 4, 2, 3, 2, 1, 4, 3, 2, 4, 1, 3 4, 1, 2, 3, 4, 2, 1, 4, 1, 2, 3, 4, 1, 3, 2, 4, 2, 1, 3, 4, 2, 3, 1, 4, 3 , 1,2,4,3,2,1,1, ing, else, there, else, IF, IF, THE, ELSE, IF, Else, The, else, The, IF, Else, IF, THE , B, C, D, B, D, A, C, D, B, A, D, B, C, A, D, C, B, B, A , C, D, B, D, B, C, D, A, B, D, A, C, B, D, C, A, C, A, B , D, C, A, D, B, D, A, C, D, A, B, C, D, B, A, D, A, B, C , D, A, C, B, D, B, A, C, D, B, C, A, D, C, A, B, D, C, B, A,

转载请注明原文地址:https://www.9cbs.com/read-87611.html

New Post(0)