On Tue, Jan 12, 2010 at 12:32 PM, Aai <[email protected]> wrote: > merge =: ({...@] , ($: }.)) `({...@[ , ($: }.)~) @. (<:&{.) ` , @. (+.&(0=#)) > split =: </.~ 0 1$~# > mergeSort =: merge & $: &>/@ split ` ] @. (1>:#) > > But I'm not very happy with the use of the merge verb (too soon into stack > problems).
split is good. mergeSort is decent, though I might be tempted to use something like: merge & mergeSort &>/@ split ^:(1<#)^:_] Your stack problems seem to come from the definition of merge. The J way of implementing merge might be /:~@, I am not sure if you would be happy with that implementation. But everything else I can think of gets into too much micro management. An alternative would use an explicit loop. Another alternative (which I have not proved to myself is adequate) might be something like: merge=: , /: >:@I.~,I. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
