The topic is as follows: Let N = 2 M times, A is an array of 2N dimensions, and the number of to be maximum is placed in A (N), A (N 1), ... a (2n-1), The maximum value is placed in a (1), so that the algorithm is described as follows: N = 2 M (N; 2N-1) is present in array a (N; 2N-1); output: Maximum number is placed in A (1) .
Beginfor K = M-1 TO 0 do for j = 2k 1-1 to 2k par do a (j) = max (2j), A (2J 1)) End Forend Forend
Implementation:
Defining the global variables as follows, Array is used to store the random number generated.
INT G_NCOUNT = 0, J = 0; int * array;
Randomly generate N numbers and stored in array array, the program code is as follows:
Void cdemodlg :: Onbtninitial () {// Initialization Array SRAND (NULL); INT I, TEMP; CSTRING STR; Updatedata (TRUE); g_ncount = POW (2, m_intcount); array = new int = 2 * g_ncount]; // According to the user's input, generating 2 M-Party random number is also stored in Array [n] ... A [2N-1] in FOR (i = g_ncount; i <2 * g_ncount; i ) { Temp = rand () / 100; array [i] = Temp;} // Display generated N random number for (i = g_ncount; i <2 * g_ncount; i ) {str.format ("array [% d] =% D ", I, Array [i]); m_strarray =" / r / n "; m_strarray = Str; m_strarray =" / r / n ";} m_strarray =" / r / n "; Updatedata (false); }
Void cdemodlg :: OnbtNCompute () {// Starting Thread for calculation INT K; for (k = m_intcount-1; k> = 0; k -) {for (j = pow (2, k); J
}