Math, asked by ANUSHKAS5839, 9 months ago

Given an array of integers, concatenate these integers in such a way that the max number is obtained

Answers

Answered by gardenheart653
1

In the used sorting algorithm, instead of using the default comparison, write a comparison function myCompare() and use it to sort numbers.

Given two numbers X and Y, how should myCompare() decide which number to put first – we compare two numbers XY (Y appended at the end of X) and YX (X appended at the end of Y). If XY is larger, then X should come before Y in output, else Y should come before. For example, let X and Y be 542 and 60. To compare X and Y, we compare 54260 and 60542. Since 60542 is greater than 54260,

we put Y first.

Following is the implementation of the above approach.

To keep the code simple, numbers are considered as strings, the vector is used instead of a normal array.

Similar questions