d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > What Kind Of Sorting Can I Do For This?
Add Reply New Topic New Poll
Member
Posts: 194
Joined: Jun 21 2003
Gold: 17.10
Mar 12 2013 10:12am
Hi,

I'm in a basic C class and so far we've learned basic input/output, loops, arrays and in a question that we have to do. It requires us to take the inputted numbers and create the largest possible outcome.

For example,

4 (this is how many integers will be inputted)
123 124 56 90 (these are the integers inputted)
5
123 124 56 90 9
0 (termination - exit code)

output:
9056124123
99056124123

How can I achieve this? I've learned about basic bubble sort, but am I able to apply it to this?

Thanks
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 12 2013 11:12am
Quote
It requires us to take the inputted numbers and create the largest possible outcome.


can you define more precisely what this means?

i'm unclear how to go from here:

123 124 56 90

to here:

9056124123

assuming you're just looking at the digits, the highest possible value would be:
9654322110
Member
Posts: 194
Joined: Jun 21 2003
Gold: 17.10
Mar 12 2013 01:24pm
Input

Each input starts with a positive integer N (<= 50). In next lines there are N positive integers. Input is terminated by N = 0, which should not be processed.

Output

For each input set, you have to print the largest possible integer which can be made by appending all the N integers.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 12 2013 01:56pm
he wants to put the inputed sets of numbers into order highest to lowers and then concat them into one integer or string.

yes you can use bubble sort to do this and it's fairly easy.

to concat you can either use snprintf() or one of string.h concat functions. i personally like snprintf() because it takes away the chance of a buffer overflow and you can easly concat outputs of different functions and variables into one string.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll