Task
 
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.

Use the following two sets of integers as tests   and   show your program output here.

   {1, 34, 3, 98, 9, 76, 45, 4}
   {54, 546, 548, 60}


Possible algorithms

 A solution could be found by trying all combinations and return the best. 
 Another way to solve this is to note that in the best arrangement, for any two adjacent original integers X and Y, the concatenation X followed by Y will be numerically greater than or equal to the concatenation Y followed by X.
 Yet another way to solve this is to pad the integers to the same size by repeating the digits then sort using these repeated integers as a sort key.


See also

   Algorithms: What is the most efficient way to arrange the given numbers to form the biggest number?
   Constructing the largest number possible by rearranging a list


 
/* Largest catenation of integers            16 October 2013 */
/* Sort using method 2, comparing pairs of adjacent integers. */
 
Largest: procedure options (main);
   declare s(*) char (20) varying controlled, n fixed binary;
   get (n);
   allocate s(n);
   get list (s);
   s = trim(s);
   put skip edit (s) (a, x(1));
   put skip list ('Largest integer=', Largest_integer());
 
largest_integer: procedure () returns (char(100) varying);
   declare sorted bit (1);
   declare (true value ('1'b), false value ('0'b)) bit (1);
   declare i fixed binary;
   declare temp character(20) varying;
 
   do until (sorted);
      sorted = true;
      do i = 1 to n-1;
         if char(s(i)) || char(s(i+1)) < char(s(i+1)) || char(s(i)) then
            do;
               temp = s(i); s(i) = s(i+1); s(i+1) = temp; sorted = false;
            end;
      end;
   end;
   return (string(s));
end largest_integer;
end Largest;
 