A number of "reverse sequence pairs" in a column; the so-called "reverse order pair" is an index size opposite to its sequence in the sequence; for example: <3, 4, 2, 1, 3> The reverse sequence is five of "5, 2>, <3, 1>, <4, 2>, <4, 1>, <4, 3>); the time complexity is O (NLOGN);
#include
Void PrintTherel (INT I, INT J); Void Sort , int source [100], int low, int road;
Void main () {int Source [100]; int Temp, length, Times; Printf ("please enter the length:"); scanf ("% d", & length); printf ("/ NPLEase Enter the elements:") ; For (Temp = 0; Temp GetResult (Times, Source, 0, Length-1); ////// Function Name: getResult // Function Description: Implementing the Solution of Normal Reverse Sequence by Recursive Algorithm: Int Bundary Difference Point // Parameters: Int Source [100] A Treatment Sequence // Parameter: INT LOW sequence start coordinate // Parameter: int high sequence last coordinate // return value: void ///// Void getResult (int bundary, int source [100], int low, int high) {INT I, K = 0; int Front [50], back [50]; if (high-low <1) / *, if only one number, the recursive stack * / return; Else {for (i = low; i ////// Function Name: Sort // Function Description: Now just for convenience of bubble sorting, O (NLOGN) can be used. // Parameters: int Array [100] Requires the array // parameter: int end array starts from 0 from 0, to END End // Return Value: Void //// Void Sort (int Array [100], int end {INT I, J, TEMP; // I think this kind of bubbling is the clearer FOR (i = end; i> 0; I -) for (j = 0; j array [j 1]) {temp = array [j]; array [j] = array [j 1]; array [j 1] = temp;}} ////// / Function Name: PRINTTHEREL / / Function Description: Format Print // Parameters: INT I Parameter 1 // Parameters: INT J Parameter 2 // Return Value: Void / /// Void PrintTherel (INT I , INT J) {Printf ("<% D,% D> / N", I, j);} Enter output example: Please enter the length: 10 Please Enter the Elements: 9 8 7 6 5 4 3 2 1 0 <5, 0> <6, 0> <7, 0> <8, 0> <9, 0> <5, 1> <6, 1> <7, 1> <5, 1> <6, 1> <7, 2> <8, 2> <9, 2> <5, 3> <6, 3> <7, 3> <5, 3> <6, 4> <7, 4> <8, 4> <9, 4> <7, 5> <8, 5> <9, 5> <9, 6> <8, 7> <9, 7> <9, 8> <6, 5> <3, 0> <4, 0> <3, 1> <4, 1> <4, 2> <2, 0> <2, 1> <1, 0> Press Any Key to Continue