Related to recent discussion of sorting algorithms, there is one
called Merge Sort. It depends on the operation of merging two
sorted lists. Merge can be thought of as bulk insert.
I was thinking of effective ways to do merge in J,
when the post from Roger came and broght along the
idea of using /: which is perfect in combination with
I. interval index.
merge=: , /: I. ,~ 1 + [EMAIL PROTECTED]@[
'A B'=: /:~&.> 4 ({.;}.) 10 [EMAIL PROTECTED] 10
A
2 5 6 9
B
0 0 4 4 7 9
A merge B
0 0 2 4 4 5 6 7 9 9
B merge A
0 0 2 4 4 5 6 7 9 9
Again, please see if this can be improved.
--- On Tue, 4/29/08, Roger Hui <[EMAIL PROTECTED]> wrote:
> If at first you don't succeed ... Insert after row j :
>
> m=: 10+i.5 3
> j=: 1
>
> ((1+j){.m), 7 8 9, (1+j)}.m
> 10 11 12
> 13 14 15
> 7 8 9
> 16 17 18
> 19 20 21
> 22 23 24
> (<0,1+i.1+j) C. 7 8 9,m
> 10 11 12
> 13 14 15
> 7 8 9
> 16 17 18
> 19 20 21
> 22 23 24
> (7 8 9,m) /: (1+j),i.#m
> 10 11 12
> 13 14 15
> 7 8 9
> 16 17 18
> 19 20 21
> 22 23 24
>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm