The maximum number (array, algorithm, and arrangement) of the C ++ array, and the array algorithm
// Arrange the array into the maximum number (array and algorithm ). // Question: enter an array of Positive Integers to join them into a number and output the largest of all the numbers that can be discharged. // For example, if the input array is {32,321}, the maximum number of the two columns is 32321 .. // Or input the Array {933101000,} to output the maximum number of the four numbers that can be arranged. # include <iostream> # define MAXSIZE 100 using namespace std; template <typename T> class Grial {public: int Length (int x, int & n) {n ++; (x/10) & (Length (x/= 10, n); return n ;}// calculates the number of digits. Bool Complate (int x, int y) // compare the size of x and y, which is the size of the combination arrangement. The size of xy is better than that of yx to form a large heap. {Int _ I = 0; int I = 0; int j = 0; int sum_1 = x; int sum_2 = y; Length (x, I); Length (y, j); for (; _ I <j; _ I ++) {sum_1 * = 10;} for (_ I = 0; _ I <I; _ I ++) {sum_2 * = 10;} if (sum_1 + y)> (sum_2 + x) return true; elsereturn false;} Grial (T a [], int n) {data = new T [n]; size = n; for (int I = 0; I <n; I ++) {data [I] = a [I];} int m = size/2; while (m <size) {MaxSort (m); m ++ ;}} void MaxSort (int n) // large heap arrangement {int temp; int I = n; int j = (I-1)/2; while (I> 0) {if (! Complate (data [j], data [I]) {temp = data [I]; data [I] = data [j]; data [j] = temp ;} I = j; j = (I-1)/2;} int GetTop () // get the first element of the heap and place the final element in the position where the subscript is 0, then sort the logs in batches. {if (size = 0) return-1; int temp = data [0]; data [0] = data [size-1]; size --; int m = size/2; while (m <size) {MaxSort (m); m ++;} return temp;} void GetSum () {int I = GetTop (); if (I! =-1) {cout <I; GetSum () ;}// output data. private: T * data; int size;}; int main () {int a [] = {, 98}; Grial <int> G (a, 5 ); // The result is 99811001111100001. g. getSum (); cout <endl; return 0 ;}