in reply to Sorting challenge

I suggest you read each line of code and decide what it is for. Follow the logic, and see if it makes sense.

I was going to offer a more elegant (and working) solution, but it turns out that your specification is incomplete, and partially contradicts the code you demonstrated. So until that's straightened out, I'm a little hesitant to demonstrate a solution that might be misinterpreting what you're trying to accomplish.


Dave

Replies are listed 'Best First'.
Re^2: Sorting challenge
by PerlSufi (Friar) on Jul 23, 2013 at 01:16 UTC
    Great response davido. Your posts are always very well thought out. Each number needs to be on its own line. The input/output needs to look like:
    #input 4 3 6 7 2 #output 2 3 6 7

      I'm still unclear on what's supposed to happen if you get input outside of (0,1000000]. I assume you don't need to prompt; the harness is not expecting any output except for the result. But what's supposed to happen on bad input?

      Maybe you should just post the exact problem specification.


      Dave

        Sorry davido, I should have did it this way instead. Here are the specifications:
        Given the list of numbers, you are to sort them in non decreasing orde +r. Input t – the number of numbers in list, then t lines follow [t <= 10^6]. Each line contains one integer: N [0 <= N <= 10^6] Output Output given numbers in non decreasing order. Example Input: 5 5 3 6 7 1 Output: 1 3 5 6 7
        I should specify that the input is from a machine- not a human user. So prompting with messages will not give the correct answer either. The site I am working off of is codechef.com.