Bid is coming to an end.CodeSome of them need to be fully arranged for integers. For example, the full sorting of 0 1 3 is 013 031 103 130 301. I thought it was a little complicated to write a full arrangement. I didn't want to do it. I directly switched the case, because there were three elements at most.
In the end, we hope to expand the test scope. The number of elements in the full arrangement increases to 4, and switch case again, it will be slow, and it will be too technical. Therefore, we simply write a fully arrangedAlgorithm.
STD: vector < Int > Quanpailie (STD: vector < Int > & V) {STD: Vector < Int > Result;
If(V. Empty ())ReturnResult; If (V. Size () =1 ) {Result. push_back (V [ 0 ]); Result. push_back ( - 1 ); Return Result ;} For ( Int I = 0 ; I <v. Size (); ++ I ){ Int Head = V [I]; STD: Vector <Int > T (V); T. Erase (T. Begin () + I); t = Quanpailie (t); Result. push_back (head ); For ( Int J = 0 ; J <t. Size ()- 1 ; ++ J ){ If (J> = 1 & T [J- 1 ] =- 1 ) {Result. push_back (head);} result. push_back (T [J]);} result. push_back ( - 1 );} Return Result ;} Int Main ( Int Argc, Char * Argv []) { Int A [] = { 1 , 2 , 3 , 4 }; STD: Vector < Int > T; For ( Int I = 0 ; I < 4 ; ++ I) T. push_back (A [I]); t = Quanpailie (t ); Return 1 ;}
The algorithm is recursive. It should be said that the efficiency is not too high. It is best to change vector to list.
In addition, the algorithm applies to any object. You only need to change int to another object. Of course, you also need to change the delimiter of other objects. In this example, the separator is-1.
That is to say, the result is in a full arrangement of 1 2 3-1 1 3 2-1 3 3 3 1 2-1 and so on.