Talk:Order two numerical lists

From Rosetta Code
Revision as of 03:24, 30 November 2011 by rosettacode>Dgamey (Stable sort, Huh?)

The task description should clarify what should happen for two equal lists.

Right now the description seems inconsistent. It says "return true if the first list should be ordered before the second", but should a list be ordered before itself? It seems that it should not.

if both lists are the same then, they still have to go in some order. so there is no inconsistency. you can not not order them. which order they go then depends on the comparison though, and that affects whether the sort is stable or not. as it is defined the task does not expect the solution to produce a stable sort. such a requirement could be added, but then the existing solutions need to be reviewed. since both stable and unstable sort have legitimate uses i don't want to make unstable sort wrong. it could be added as extra credit though--eMBee 02:30, 30 November 2011 (UTC)

But reading the algorithm description: "... and so on, until one of the list has no more elements. If the first list runs out of elements the result is true." It seems that it should return true for two equal lists, since both lists would run out of elements at the same time.

if the first list is tested first, and the second list is not tested, the effect is that if both are equal, the result will be true.--eMBee 02:30, 30 November 2011 (UTC)

Whatever is decided, some of the solutions will be incorrect and will need to be changed. --Spoon! 23:55, 29 November 2011 (UTC)

This probably should be marked draft until decided. So I changed it. --Dgamey 03:21, 30 November 2011 (UTC)
Adding in extra conditions like stable sort when the task is NOT marked draft is rather bad form --Dgamey 03:21, 30 November 2011 (UTC)

Test Cases

I found the description a bit confusing at first. I used the following test cases where demo_list_llt was a wrapper to support my interpretation. --Dgamey 03:24, 30 November 2011 (UTC)

   write()
   demo_list_llt([-1],[0])                         # << ok
   demo_list_llt([0],[0])                          # == fail 
   demo_list_llt([0],[-1])                         # >> fail
   write()
   demo_list_llt([0],[0,-1])                       # << ok   
   demo_list_llt([0],[0,0])                        # << ok     
   demo_list_llt([0],[0,1])                        # << ok 
   demo_list_llt([0,-1],[0])                       # >> fail 
   demo_list_llt([0,0],[0])                        # >> fail
   demo_list_llt([0,0],[1])                        # << ok

With the following output:

[ 1 2 1 3 2 ] << [ 1 2 0 4 4 0 0 0 ] - FAILS

[ -1 ] << [ 0 ]
[ 0 ] << [ 0 ] - FAILS
[ 0 ] << [ -1 ] - FAILS

[ 0 ] << [ 0 -1 ]
[ 0 ] << [ 0 0 ]
[ 0 ] << [ 0 1 ]
[ 0 -1 ] << [ 0 ] - FAILS
[ 0 0 ] << [ 0 ] - FAILS
[ 0 0 ] << [ 1 ]

The wrapper and support routine in Icon was

procedure demo_list_llt(L1,L2)
   write(list2string(L1)," << ",list2string(L2),if list_llt(L1,L2) then "" else " - FAILS")
end   

procedure list2string(L1)
every (s := "[") ||:= " " || (!L1|"]")
return s
end

Stable Sort

Where did this requirement come from? There was nothing about sorting only comparison. Neither list is touched. There is no merge or no sort. Did I miss something? --Dgamey 03:24, 30 November 2011 (UTC)