pls help
Form biggest number code
@chahatkumar hey chahat your compare function is not right a simple compare function is
int compare(string a, string b){
string first = a.append(b);
string second = b.append(a);
return first.compare(second) >0 ? 1:0;
}
made such changes
thanks
can u pls explain this compare function?
what does append do ?
also if there any other better method to do the same problem ?
@chahatkumar hey chahat A simple solution that comes to our mind is to sort all numbers in descending order, but simply sorting doesn’t work. For example, 548 is greater than 60, but in output 60 comes before 548. As a second example, 98 is greater than 9, but 9 comes before 98 in output.
So how do we go about it? The idea is to use any comparison based sorting algorithm. 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.