Talk:Order two numerical lists: Difference between revisions

Line 62:
:::: Still bunk. Regardless if elements are the same or not, sort stability also depends on how the comparator is called. <code>if (a[i] < a[j]) swap(a[i], a[j])</code> and <code>unless (a[i] > a[j]) swap(a[i], a[j])</code> are unlikely to be both stable in bubble sort. The comparison routine has '''no''' information regarding "the relative order of records", only the sort routine does, so terming a comparator "stable sort" is senseless. --[[User:Ledrug|Ledrug]] 07:20, 30 November 2011 (UTC)
::::: <code>unless ></code> is the same as <code><=</code>, so that means, yes, the way the comparator is called affects the stability, which means the choice of the comparator depends on knowing how the comparator is called. but regardless of the comparator chosen, it will always be called the same way, so the stability still depends on the comparator. so you are right that without the sort function the comparator by itself can not be categorized as stable. but we can test the sort function and then determine if the combination produces a stable sort. however i think it is probably better to leave that out of the task because different languages have different ways to do the sort. this may be worth a separate topic.--[[User:EMBee|eMBee]] 08:21, 30 November 2011 (UTC)
:::::: You can use a comparison routine in a bubble sort and claim it's "stable", then use it in a quicksort and find that it's not--you are still missing the point: sort stability is not the property of the comparator ''at all''. Seeing that the matter is probably settled anyway, I'm just point that out as a final clarification. --[[User:Ledrug|Ledrug]] 08:42, 30 November 2011 (UTC)
:: Another thing, it might be better to omit some detailed requirement about the cmp result. To be practical, the cmp routine should be able to decide on the ording. For example, it's likely more useful for a comparison function to be tri-state instead of true/false;--[[User:Ledrug|Ledrug]] 04:33, 30 November 2011 (UTC)
::: tri-state does not work as input to a sort function unless the sort function is written for that. most sort function i i'd expect to want a boolean comparator.--[[User:EMBee|eMBee]] 05:50, 30 November 2011 (UTC)
Anonymous user